File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Anyone know why I am getting this error (Regarding building an array based stack) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Anyone know why I am getting this error (Regarding building an array based stack)" Watch "Anyone know why I am getting this error (Regarding building an array based stack)" New topic
Author

Anyone know why I am getting this error (Regarding building an array based stack)

Tom Little
Greenhorn

Joined: Oct 24, 2009
Posts: 20
I am trying to build an Array based stack and I keep just getting this one error


edit: The '^' arrow is always under 'StackUnderflowException', i do not get any errors with 'StackOverflowException'.

StackIntADT.java:7: error: cannot find symbol
public int pop() throws StackUnderflowException;
^
symbol: class StackUnderflowException
location: interface StackIntADT


ArrayStack.java:43: error: cannot find symbol
public int pop() throws StackUnderflowException
^
symbol: class StackUnderflowException
location: class ArrayStack
StackIntADT.java:7: error: cannot find symbol
public int pop() throws StackUnderflowException;
^
symbol: class StackUnderflowException
location: interface StackIntADT


ArrayStack.java:63: error: cannot find symbol
throw new StackUnderflowException("Stack is empty");
^
symbol: class StackUnderflowException
location: class ArrayStack
ArrayStack.java:71: error: cannot find symbol
throw new StackException("empty");
^
symbol: class StackException
location: class ArrayStack


I am getting this everywhere, I have imported Stack. I have all the files saved the same folder. Does anyone know why possibly I am getting this? Could I be not importing something correctly?syntax? thanks a lot.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10906
    
  12

What is a StackUnderflowException? I can't find such a thing in the API (not that I searched very hard). What the pop method seems to actually throw is an EmptyStackException:

pop

public E pop()
Removes the object at the top of this stack and returns that object as the value of this function.
Returns:
The object at the top of this stack (the last item of the Vector object).
Throws:
EmptyStackException - if this stack is empty.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Tom Little
Greenhorn

Joined: Oct 24, 2009
Posts: 20
fred rosenberger wrote:What is a StackUnderflowException? I can't find such a thing in the API (not that I searched very hard). What the pop method seems to actually throw is an EmptyStackException:

pop

public E pop()
Removes the object at the top of this stack and returns that object as the value of this function.
Returns:
The object at the top of this stack (the last item of the Vector object).
Throws:
EmptyStackException - if this stack is empty.


You're right, actually I found out what was wrong, I had created a separate class called 'StackOverflowException' that extends RuntimeException which worked and was why I wasn't getting an error for 'StackOverflowException'. I hadn't created one for StackUnderflow because for some reason I assumed both of these were in the java API and they weren't. Thanks though I appreciate it.
 
Don't get me started about those stupid light bulbs.
 
subject: Anyone know why I am getting this error (Regarding building an array based stack)
 
Similar Threads
Stacks using Arrays
reverse for stacks??
Stacks
Getting Error to Stack program
Stack ADT help