• 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

Problem using java.util.Stack with SAX

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,.



 
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
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any updates ???
 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic