File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Getting Error to Stack program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting Error to Stack program" Watch "Getting Error to Stack program" New topic
Author

Getting Error to Stack program

Yatin Shah
Ranch Hand

Joined: Sep 11, 2004
Posts: 72
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
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

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

Joined: Sep 11, 2004
Posts: 72
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

Joined: Oct 02, 2003
Posts: 10908
    
  12

Personally, I don't see anything called ArrayStack in the java api. The list I see goes from Arrays to ArrayStoreException.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

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

Joined: Sep 11, 2004
Posts: 72
I have checked.

http://commons.apache.org/collections/api-2.1.1/org/apache/commons/collections/ArrayStack.html
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2


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

Joined: Sep 11, 2004
Posts: 72
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

Joined: Aug 16, 2005
Posts: 13868
    
  10

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Yatin Shah
Ranch Hand

Joined: Sep 11, 2004
Posts: 72
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

Joined: Oct 02, 2003
Posts: 10908
    
  12

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

Joined: Sep 11, 2004
Posts: 72
Ok Guys thanks for all. I got it.

Regards,
Yatin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Error to Stack program
 
Similar Threads
gc question
Garbage collection question from J@Whiz1.4
How many objects are Garbage collected.Explain
Array Stack
Sun Cirtification