This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Having issues with Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Having issues with Serialization" Watch "Having issues with Serialization" New topic
Author

Having issues with Serialization

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1669
    
  11

I'm sure I'm missing something simple here... the problem is when I try to access either student or mentor objects after they are deserialized, I get null pointer exceptions. The application behaves appropriately if I access the objects before the application is closed and reopened.

This is the deserialization:


And here's where I serialize the objects:


The behavior is similarly incorrect whether I am trying to view Students or Mentors.

I feel like this should be something simple and I'm not seeing it.

Thanks a bunch!
Janeice


When you do things right, people won't be sure you've done anything at all.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

System.out.println(m);

How can you get a NullPointerException here ? What does Mentor#toString look like ? What is the exact stack trace ?


[My Blog]
All roads lead to JavaRanch
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1669
    
  11

I don't get a null pointer there (although my comment implied that and I'm sorry).... it just says "null".... this has given me enough information to determine the cause of my null pointer exception when I try to use/manipulate the objects down the road is the object apparently not deserializing correctly.

Here's the Mentor toString()


Here's the stack trace:


and this is line 58.... it's in context above.... but I get a similar error whenever I try to manipulate the objects.


Thanks for the help!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

In your serialization process, you are using a loop starting from index 0. Then you get a Student/Mentor, using that index. Are you sure that the index exists in the Map ? If not, you'll serialize a null object ! You should be looping the Map using its keys, or using its values. Like :
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1669
    
  11

Christophe Verré wrote:In your serialization process, you are using a loop starting from index 0. Then you get a Student/Mentor, using that index. Are you sure that the index exists in the Map ? If not, you'll serialize a null object ! You should be looping the Map using its keys, or using its values. Like :


I knew it would be something easy!

Lemme try that today. Thanks!

Janeice
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1669
    
  11

This is what I ended up with.... it works!



Thanks!!
 
GeeCON Prague 2014
 
subject: Having issues with Serialization