Serailization gives me null pointer exception. Why?
1 posts in topic
Flat View  Flat View

Posted By:   Anonymous
Posted On:   Saturday, September 14, 2002 01:36 AM

In my application, I am serializing some java objects for future restoration. I am using XMLEncoder and XMLDecoder classes of J2sdk1.4.0 for this purpose. My problem is that whenever I am trying to save these objects, I get NullPointerException on the server, though the object is saved and retrieved successfully. I do not know what this exception means and where it originates from as the client side is quite perfect and none of my attributes are null while being saved. Any clues!!

Re: Serailization gives me null pointer exception. Why?

Posted By:   Eric_Lindauer  
Posted On:   Sunday, September 15, 2002 08:23 AM

When it comes to NullPointers, it's usually a safe bet that the problem is an application specific problem. Something you think is an instantiated object is actually null. As such, it's normally not possible to answer a question that amounts to "something is null, what's wrong?".
I'd suggest you at least post the stack trace when you run into RuntimeExceptions like this.

To solve this yourself though, try making a *much* simpler example than your application and see what happens. That is, make an object with one String field, and try to serialize / deserialize it. This serves two purposes. First, if your test object is successful, you can slowly make it look like your complicated example. At some point, you'll change something which brings back the NullPointer... there's your bug. On the hand, if the very simple test breaks, then you have a great set of code to provide in your post as a way to reproduce the problem. This will go much farther toward getting help (besides being a good demonstration that you have put in effort yourself trying to fix the problem).

Hope this helps.


Oh yeah... the simple case you create will also serve as an excellent test case, so you can ensure this bug doesn't crop up again as you change your code.
About | Sitemap | Contact