Sign in to follow this  

Java Serializable

This topic is 2650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, this is my AnimationSaving class :

public class AnimationFileSaver {
public AnimationFileSaver(String filePath){
this( new File(filePath));
}
public AnimationFileSaver(File file){
//save file
try{ _tryToSave(file);}
catch(java.io.IOException e){
e.printStackTrace();
}
}

private void _tryToSave(File file)throws java.io.IOException{
java.io.FileOutputStream stream = new java.io.FileOutputStream(file);
java.io.ObjectOutputStream outputStream = new java.io.ObjectOutputStream(stream);
//save data into file
outputStream.writeObject(animationeditor.Controller.AnimationMainController.windowController);
outputStream.writeObject(animationeditor.Controller.AnimationMainController.frameController);
}
}




and my loader class

public class AnimationFileLoader {
public AnimationFileLoader(String filePath){
this( new File(filePath));
}
public AnimationFileLoader(File file){
//save file
try{ _tryToSave(file);}
catch(java.lang.Exception e){
e.printStackTrace();
}
}

private void _tryToSave(java.io.File file)throws java.io.IOException, java.lang.ClassNotFoundException{
java.io.FileInputStream stream = new java.io.FileInputStream(file);
java.io.ObjectInputStream inputStream = new java.io.ObjectInputStream(stream);
//save data into file
AnimationMainController.windowController = (AnimationWindowController)inputStream.readObject();
AnimationMainController.frameController = (OnionSkinningController) inputStream.readObject();

}
}



The windowController contains the main app window, and the frame controller
has a list of frames used in th program. The above class works partially, but
not fully. The objects that were saved are loaded into the screen, but they
loose their capability of interactions with the user. More over, when I debug
it, my container that holds a list of shapes seems to be empty, but the screen
still shows the shape. Is there something more I should know about java.io.Serializable ? I could show more code, if I need to. Thanks.

Share this post


Link to post
Share on other sites
None of these classes seem to implement Serializable.

Also, none of that _underscoreNaming. Java has fixed naming convention, there is no reason to deviate from that.

Share this post


Link to post
Share on other sites
Does the saver and loader need to implement serializable? And I'm not sure whats the convention in java. Just regular naming I guess.

These classes implements java.io.Serializable

AnimationMainController.windowController; AnimationMainController.frameController


Share this post


Link to post
Share on other sites
Sign in to follow this