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

    Exclamation Complier error (Please help)

    Here is the MESSAGE

    ArrayStack.java:62: variable element might not have been initialized
    return element;
    ^
    Note: ArrayStack.java 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;

    import java.io.*;


    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;
    if(isEmpty())

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



    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    For the first error, do as Pete has suggested.

    Quote Originally Posted by ShortIt View Post
    Note: ArrayStack.java 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.

    Goldest
    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, 10:25 AM
  2. Replies: 1
    Last Post: 03-10-2010, 02:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 05:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 09: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
  •