This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Problem using java.util.Stack with SAX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Problem using java.util.Stack with SAX" Watch "Problem using java.util.Stack with SAX" New topic
Author

Problem using java.util.Stack with SAX

Chilkosae Cozea
Greenhorn

Joined: Mar 19, 2009
Posts: 7
Hi

Can it be possible the java.util.Stack empty() function is not returning the correct value.
The probelm is sometime I'm getting java.util.EmptyStackException from poppinout funtion even if I check stack.empty() before calling stack.pop function.

I'm using org.xml.sax.ContentHandler to fetch the first 500 character until the first period(".") in the XML. The code look something like this.

I have this condition in popingout function,.



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

No, you'll find your error is the obvious one: you are popping from the stack more than you are pushing onto it.

By the way, if you want people to read your code, you should post it inside the "code" tags. I have to say I didn't read the code you posted; unindented code is too hard to read. You can edit your post by clicking on the "Edit" button.
Chilkosae Cozea
Greenhorn

Joined: Mar 19, 2009
Posts: 7
Hi Paul
Thanks for your reply.

Sorry for posting the unformatted code. I was not aware of the standard practise of putting the code in this editor.

As you said I'm popping from the stack more than pushing onto it, does that mean the if condition I put "stack.empty()" before calling the Pop function is not working? In all the scenario where I'm popping out I have put the if condition to check whether stack is empty or not.
Chilkosae Cozea
Greenhorn

Joined: Mar 19, 2009
Posts: 7
Any updates ???
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

The simple answer is that Stack.empty() won't be returning incorrect values. You haven't included a standalone test case to reproduce your problem so we can't offer much more help. The only reason I can think for for pop() to fail after empty() returns false is if the stack is shared by multiple threads.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
You appear to be throwing away the information that can help you. I refer to:



Gee, do you think an IOException might be important enough to print a stack trace

Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem using java.util.Stack with SAX
 
Similar Threads
Reading XML
SAX:Why content handler's characters() method is called and print multiple space string.
parsing data and storing in the xml
SAXParser not calling characters()
Getting Node Value using SAX