Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Error to Stack program

 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am getting error while running following program. I am getting following error

java:31: cannot find symbol
symbol : class ArrayStack
location: class MyArrayStack
Stack newStack = new ArrayStack();
^
Is anyone can help me?

>
 
Paul Clapham
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you wrote

did you mean you wanted an instance of your MyArrayStack class, the one you posted? Or did you mean you wanted an instance of some other class named ArrayStack, which you didn't post?
 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

I guess ArrayStack is inbuilt class of java.util package and I am using that class to achieve desire goal.

Thanking You,
Yatin
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I don't see anything called ArrayStack in the java api. The list I see goes from Arrays to ArrayStoreException.
 
Paul Clapham
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered looking at the documentation to see if your guess is correct?

Actually looking at the documentation is a much more practical way of programming than guessing at class names.
 
Yatin Shah
Ranch Hand
Posts: 72
 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If you are using third party library,
you have to include the api jar in your classpath
and import the class in your main class.
 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Guys,

I had solved that problem. Now I am not getting any error but also not getting desire out put. It saying "Stack is Empty". Is any one can help me?

Regards,
Yatin
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your program and imagine what happens when it runs.

In line 19, you assign to s the value "1+2+3+4+5+6+7+8+9".

In lines 30 - 43 you loop over the characters in the string s. It starts with the first character, which is "1".

In line 32 you check if the character is '+'. It is '1', so it goes to the "else" in line 37.

In line 37, you pop the stack. But at that point there is nothing on the stack; you just created an empty stack on line 28 and didn't push anything onto it. So you get an EmptyStackException, which is where the "stack is empty" message comes from.
 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jong,

Thanks, I am not that good with java. I had changed my first statement of else condition. My code is as follow. I am not getting right answer.

>
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yatin Shah wrote:I am not getting right answer.

Please read why ItDoesntWorkIsUseless. Then come back here and post what is happening and what you expect to happen.
 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Guys thanks for all. I got it.

Regards,
Yatin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic