Results 1 to 3 of 3
  1. #1
    ShortIt is offline Member
    Join Date
    Jan 2011
    Rep Power

    Exclamation Complier error (Please help)

    Here is the MESSAGE variable element might not have been initialized
    return element;
    Note: uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error

    HERE is the CODE, PLEASE HELP, I dont know how to get rid of the error.

    package jss2;


    public class ArrayStack<E>

    protected int capacity;
    public static final int CAPACITY = 100;
    protected E S[];
    protected int top = -1;

    public ArrayStack(int cap)
    capacity = cap;
    S = (E[])( new Object [capacity]);

    public ArrayStack()
    this (CAPACITY);

    public int size()
    return (top +1);

    public boolean isEmpty()

    return(top <0);


    public void push(E element)
    if (size() == capacity)

    S[++top] = element;


    public E top()
    if (isEmpty())

    return S[top];

    public E pop()
    E element;

    element = S[top];
    S[top--] = null;
    return element;


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    The element is declared but not initialized at declaration. After that it might be initialized in the if block, but then again, it might not, so the compiler rightly complains that you're using it without knowing for sure. To fix this initialize it to null when you declare it.

  3. #3
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Pune, India
    Rep Power


    For the first error, do as Pete has suggested.

    Quote Originally Posted by ShortIt View Post
    Note: uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    This thing is indicating that you may be using some methods which are deprecated. So compile with the option provided which will show you which of the things in your code are no more supported. Once you get them, try to replace that part if possible.

    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

Similar Threads

  1. Custom JSP Complier in Tomcat 6 ?
    By Rein in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-10-2010, 09:25 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts