Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying basic io serialization, won't work  RSS feed

 
Jonathan Bjerche
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 classes involved in this:

Player Class: Has a name and adress string variables.

Player Register Class: Has an array list of players.


I want to save the PlayerRegister with all the players in it when the application exits, and then restore the saved PlayerRegister when the application starts the next time.


Here is the code for importing the PlayerRegister when the application starts:



Here is the code for saving the PlayerRegister when the application exits.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless.(⇐click) You need to TellTheDetails(⇐click) as to exactly what's going wrong.

Also, never do this:


When you catch an exception, at the very least, call e.printStackTrace() so you can see what went wrong and where. (That by itself isn't actually proper exception handling, but it's a reasonable start.)
 
Jonathan Bjerche
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks guys.

The problem is when I deserialize the PlayerRegister; I don't get all the players that was in the original PlayerRegister.

So how can I save them too?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point the only possible answer to that is "Do something differently, then". Have another look at that TellTheDetails document which Jeff posted the link to.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Have another look at that TellTheDetails document which Jeff posted the link to.


Yes, please do that.

Additionally, as a general debugging technique, you'll want to put a bunch of println() statements in your code (or use a debugger) so that you can see what's happening at each step of the way--what various values are and which code paths are being taken. For example, you might want to look at what's in PlayerRegister right before you serialize it.
 
Jonathan Bjerche
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.

The class PlayerRegister contains an arraylist<Player>.

Before I serialize the PlayerRegister I have added 2 Player-objects to this arrayList<Player> in the PlayerRegister class.

I want to save the PlayerRegister and all the players that are added to the arraylist<player> in playerregister using the code I posted in the first post.

Problem is: When I deserialize the PlayerRegister again the arrayList is empty with no Players.

I know from using the netbeans debugger that:
1) There are 2 players in the player register arraylist<player> when I serialize it
2) There are no players in the player register arraylist<player>when I deserialize it
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jonathan Bjerche wrote:Ok.

The class PlayerRegister contains an arraylist<Player>.

Before I serialize the PlayerRegister I have added 2 Player-objects to this arrayList<Player> in the PlayerRegister class.

I want to save the PlayerRegister and all the players that are added to the arraylist<player> in playerregister using the code I posted in the first post.

Problem is: When I deserialize the PlayerRegister again the arrayList is empty with no Players.

I know from using the netbeans debugger that:
1) There are 2 players in the player register arraylist<player> when I serialize it
2) There are no players in the player register arraylist<player>when I deserialize it


SSCCE or it didn't happen. Otherwise we're back to "not enough details, so the best answer we can give is, 'Do something differently.'"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!