This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
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.
 
lowercase baba
Posts: 12628
50
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!