wood burning stoves*
The moose likes Beginning Java and the fly likes Problems with serialization / deserialization. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problems with serialization / deserialization." Watch "Problems with serialization / deserialization." New topic
Author

Problems with serialization / deserialization.

Reginildo Sousa
Greenhorn

Joined: Jun 14, 2010
Posts: 2
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!


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." (Fowler)
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
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.


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Reginildo Sousa
Greenhorn

Joined: Jun 14, 2010
Posts: 2
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

Joined: Oct 13, 2005
Posts: 38020
    
  22
Welcome to the Ranch

I am afraid the complete code adds nothing useful; Peter Taucher has said it all.
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
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:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problems with serialization / deserialization.
 
Similar Threads
How to writeObject an array?
another head first beatbox question
Head Start java Beatbox serialization/deserializatoin
Using JFileChooser instead of serialization hard coded files
HFJ BeatBox program, problems