• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with serialization / deserialization.

 
Reginildo Sousa
Greenhorn
Posts: 3
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I've been studying the book Heard First Java. This book has a code of "BeatBox" that demonstrates how to use the serialization / deserialization to save / restore standards of "hits".
Here's the part that I'm in doubt:
Creating SerializeIt button:



Inner class "listener" of SerializeIt:

Creating the Open File button:

Inner class "listener" Open the File:

The way my code is done I can save files, beat patterns. But when I try to restore a pattern, I can't. It does not restore the BeatBox.
I hope I was clear in explaining the problem. It is the first post that I create and my English is limited. If you want any further information, communicate with me.
Thanks for listening!
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your loadFile and saveFile methods you do not modify any GUI elements. You do not even read / write the file contents. All I can see is the instantiation of the BufferedReader / BufferedWriter and the close call. I think you might need to actually read / write something.

Me don't see no seralitation in provided code ; -

// edit
OK, so you serialize to a fixed filename (not in saveFile method though), but you don't ever read data.
 
Reginildo Sousa
Greenhorn
Posts: 3
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's best to put the complete code:
Here it is!



I think I actually read in a file and record the sequences of each JCheckBox (method loadFile() and saveFile()). But in the moment to restore the GUI for the file, it does not happends. I think I need to do one more thing in the method loadFile (), I just don't know what it is.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I am afraid the complete code adds nothing useful; Peter Taucher has said it all.
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reginildo Sousa wrote:I think I need to do one more thing in the method loadFile (), I just don't know what it is.

I already mentioned that you could try to actually read something from the Reader object.

Your (pseudo-)code:

And (pseudo-)code that pretends to read something:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic