• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization & data retrieval

 
Howard Bates
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I have written a program that saves JTextField values to a .ser file. As long as the program is still running, I can read those values back into eaxh JTextField. If I close the program, re-open it, and try to read them in again, the JTextFields remain blank. Am I doing something wrong?

Thanks!
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Howard Bates:
Am I doing something wrong?


I'm afraid we can't tell from the description you have given us. You need to isolate the problem then tell the details. The better question you ask, the more help we can give.
 
Howard Bates
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code that opens the 'character.ser':
item02 = new JMenuItem("Open");
item02.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
int retval = fileChooser.showOpenDialog(RolePlayerUtility.this);
if (retval == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
ObjectInputStream is = new ObjectInputStream(new FileInputStream(file));
Character characterRestore = (Character) is.readObject();
textIn_s0.setText(character.getSkillZero());
textIn_s1.setText(character.getSkillZeroBonus());
textIn_s2.setText(character.getSkillOne());
textIn_s3.setText(character.getSkillOneBonus());
textIn_s4.setText(character.getSkillTwo());
textIn_s5.setText(character.getSkillTwoBonus());
textIn_s6.setText(character.getSkillThree());
textIn_s7.setText(character.getSkillThreeBonus());
textIn_s8.setText(character.getSkillFour());
textIn_s9.setText(character.getSkillFourBonus());
textIn_s10.setText(character.getSkillFive());
textIn_s11.setText(character.getSkillFiveBonus());
}
} catch(Exception e1){}
}
}
);
______________________________________________________________________
Works perfectly if I do not close running program. If I close, re-open, and then try, all fields remain blank.

Thanks!

~HB
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never ever Ever EVER do this:



If you are getting an exception in this code you'd never know it.
 
Howard Bates
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! I have changed to the following:
} catch(IOException e1){
textOut.setText("ERROR!");
} catch(ClassNotFoundException e2){
textOut.setText("ERROR!");
}

I am not seeing any errors, just not populating fields.

~HB
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you certain actionPerformed() is being invoked? How about writing some messages to the console so you can see what's going on?
 
Howard Bates
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out!

These: textIn_s0.setText(character.getSkillZero());

Should be: textIn_s0.setText(characterRestore.getSkillZero());

Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!