writing and loading Objects
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ivn_Tcakov
Posted On:   Thursday, December 20, 2001 12:02 PM

Hello, I've been trying to save and load back in an Object File by using Object Serialization and ObjectOutputStream and ObjectInputStream. Everything works without casting any exceptions except when I load the fiel back in, it is null. I don't know why. I am actually trying to load a certain Class (which I named SaveGUI) that I have created and that contains many different Objects within itself and they are all Serializable. Now, to use the method readObject(), I guess the object has to be an instance of class Object so I tried extending SaveGUI to Object, It still didn't work. Can anyone give me some hints on what the problem could be? This is some of the code: FileDialog d = new FileDialog(GUI.this, "Save GUI State"   More>>

Hello, I've been trying to save and load back in an Object File by using Object Serialization and ObjectOutputStream and ObjectInputStream. Everything works without casting any exceptions except when I load the fiel back in, it is null. I don't know why. I am actually trying to load a certain Class (which I named SaveGUI) that I have created and that contains many different Objects within itself and they are all Serializable. Now, to use the method readObject(), I guess the object has to be an instance of class Object so I tried extending SaveGUI to Object, It still didn't work.
Can anyone give me some hints on what the problem could be?
This is some of the code:

			
FileDialog d = new FileDialog(GUI.this, "Save GUI State", FileDialog.SAVE);
d.show(); // display the dialog and block until answered
String filename = d.getFile(); // Get the user's response
if (filename != null) { // If user didn't click "Cancel."
try {
// Create the necessary output streams to save the Object.
File f = new File(d.getDirectory(), filename); // Create a file object
ObjectOutputStream out = new ObjectOutputStream(
new java.util.zip.GZIPOutputStream(
new FileOutputStream(f))); // Save objects
out.writeObject((SaveGUI)saveGUI); // Write the entire Object.
out.flush(); // Always flush the output.
out.close(); // And close the stream.
}
// Print out exceptions.
catch (IOException ioe) { System.out.println("I/O Exception in file writing: "+ioe); }
}

// Open up a dialog for the user to choose the file
FileDialog d = new FileDialog(GUI.this, "Load a Saved GUI State", FileDialog.LOAD);
d.show(); // display the dialog and block until answered
String filename = d.getFile(); // Get the user's response
if (filename != null || (filename.length() != 0)) { // If user didn't click "Cancel."
try {
// Create the necessary input streams to load the GUI.
File f = new File(d.getDirectory(), filename); // Create a File object
ObjectInputStream in = new ObjectInputStream(
new java.util.zip.GZIPInputStream(
new FileInputStream(f))); // Read Object.
SaveGUI obj = (SaveGUI)in.readObject(); // Assign Object.
//in.close(); // And close the stream.
}
// Print out exceptions.
catch (IOException ioe) { System.out.println("I/O Exception in file loading: "+ioe); }
}

public class SaveGUI extends java.lang.Object implements java.io.Serializable {

public SaveGUI() {}

Vector xAxisDataTable = new Vector(); // For each Frame there is a x-Axis DataTable
Vector yAxisDataTable = new Vector(); // for each x-Axis column there is a y-Axis DataTable
Vector titlexAxis = new Vector(); // The title of the xAxis (Vector of Strings)
Vector titleyAxis = new Vector(); // (Vector of Strings)
Vector plotsRecord = new Vector(); // Plotting Records of columns in x-Axis List (PlotRecord-s)
Vector plotsOptions = new Vector(); // Plotting Options, for each layout frame (PlotOptionsFrame)
...
}
   <<Less

Re: writing and loading Objects

Posted By:   Ivn_Tcakov  
Posted On:   Thursday, December 20, 2001 12:13 PM

I solved it, don't worry.
About | Sitemap | Contact