java - Saving information using Serializable -
i attempting program save data inputted user. currently, getting a:
java.io.notserializableexception: java.awt.image.bufferedimage error
now, have done implement filewriter in user interface class, , examining text file appears trying save of information text boxes , labels have implemented on ui. in main class ui based off of, there arraylist holds objects of project. need serialize these objects contain bufferedimage. think have found way work around bufferedimage error, not want entire ui serialized.
so question is, should move serialization method class contains arraylist of objects, ui not serialized?
mark bufferedimage fields transient
keyword indicates field should not serialized.
class { transient bufferedimage bufferedimage; ...
then can customize serialization implementing following methods in class a
private void writeobject(java.io.objectoutputstream s) throws java.io.ioexception{ s.defaultwriteobject(); // extract bytes bufferedimage , write them ... private void readobject(java.io.objectinputstream s) throws java.io.ioexception, classnotfoundexception { s.defaultreadobject(); // read bytes , re-create bufferedimage ...
Comments
Post a Comment