| Author |
Having issues with Serialization
|
Janeice DelVecchio
Saloon Keeper
Joined: Sep 14, 2009
Posts: 1611
|
|
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: 14669
|
|
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: 1611
|
|
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: 14669
|
|
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: 1611
|
|
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: 1611
|
|
This is what I ended up with.... it works!
Thanks!!
|
 |
 |
|
|
subject: Having issues with Serialization
|
|
|