• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problems with serialization / deserialization.

 
Greenhorn
Posts: 3
Hibernate Eclipse IDE 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!
 
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
Hibernate Eclipse IDE 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.
 
Marshal
Posts: 70308
283
  • 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:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic