• 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

Getting Error to Stack program

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

>
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have checked.

http://commons.apache.org/collections/api-2.1.1/org/apache/commons/collections/ArrayStack.html
 
Ranch Hand
Posts: 258
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yatin Shah wrote:I have checked.

http://commons.apache.org/collections/api-2.1.1/org/apache/commons/collections/ArrayStack.html


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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Guys thanks for all. I got it.

Regards,
Yatin
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic