Win a copy of Kotlin for Android App Development this week in the Kotlin 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 12706
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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!