• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic