Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tom Little
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12147
31
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tom Little
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic