Results 1 to 3 of 3
Thread: Complier error (Please help)
- 02-21-2011, 04:44 AM #1Member
- Join Date
- Jan 2011
- Rep Power
Complier error (Please help)
Here is the MESSAGE
ArrayStack.java:62: variable element might not have been initialized
Note: ArrayStack.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
HERE is the CODE, PLEASE HELP, I dont know how to get rid of the error.
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 int size()
return (top +1);
public boolean isEmpty()
public void push(E element)
if (size() == capacity)
S[++top] = element;
public E top()
public E pop()
element = S[top];
S[top--] = null;
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.
- 02-21-2011, 04:53 AM #3
For the first error, do as Pete has suggested.
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.
GoldestJava Is A Funny Language... Really!
Click on * and add to member reputation, if you find their advices/solutions effective.
- By Rein in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 12-10-2010, 10:25 AM
- By corney_16 in forum New To JavaReplies: 1Last Post: 03-10-2010, 02:53 PM
- By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 08:28 AM
- By NARs in forum NetworkingReplies: 1Last Post: 10-26-2009, 05:38 PM
- By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 09:53 AM