• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having issues with Serialization

 
Janeice DelVecchio
Saloon Keeper
Posts: 1808
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println(m);

How can you get a NullPointerException here ? What does Mentor#toString look like ? What is the exact stack trace ?
 
Janeice DelVecchio
Saloon Keeper
Posts: 1808
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1808
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1808
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I ended up with.... it works!



Thanks!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic