writing aborted; java.io.NotSerializableException -


i trying read objects file. below snippet of method use fetch list of object file.

public list displayparties() {         objectinputstream ois = null;         list<registerparty> results = new arraylist();         try {             fileinputstream fis = new fileinputstream("/media/user/disk2/myapp/assignment/party.ser");             ois = new objectinputstream(fis);             while (true) {                 system.out.println(" inside while true");                 results.add((registerparty) ois.readobject());                 system.out.println(results);             }         } catch (ioexception ex) {             ex.printstacktrace();         }         catch (exception ex){                 ex.printstacktrace();          } finally{             try {                 ois.close();             }catch (ioexception ex){                 ex.printstacktrace();             }         }         return results;     } 

registerparty class :

public class registerparty implements serializable {     string bookingpersonname;     string childname;     string childage;     string theme;     string foodalergies;     string noofguest;     string specialguest;      public string getbookingpersonname() {         return bookingpersonname;     }      public void setbookingpersonname(string bookingpersonname) {         this.bookingpersonname = bookingpersonname;     }      public string getchildname() {         return childname;     }      public void setchildname(string childname) {         this.childname = childname;     }      public string getchildage() {         return childage;     }      public void setchildage(string childage) {         this.childage = childage;     }      public string gettheme() {         return theme;     }      public void settheme(string theme) {         this.theme = theme;     }      public string getfoodalergies() {         return foodalergies;     }      public void setfoodalergies(string foodalergies) {         this.foodalergies = foodalergies;     }      public string getnoofguest() {         return noofguest;     }      public void setnoofguest(string noofguest) {         this.noofguest = noofguest;     }      public string getspecialguest() {         return specialguest;     }      public void setspecialguest(string specialguest) {         this.specialguest = specialguest;     }      public string tostring(){         return bookingpersonname+" "+childname+" "                 +childage+" "+foodalergies+" "+theme+" "+noofguest+" "+specialguest;     } } 

but getting below exception :

java.io.writeabortedexception: writing aborted; java.io.notserializableexception: models.registerparty     @ java.io.objectinputstream.readobject0(objectinputstream.java:1354)     @ java.io.objectinputstream.readobject(objectinputstream.java:370)     @ helper.helperfunctions.displayparties(helperfunctions.java:39)     @ services.partyoperations.listallparties(partyoperations.java:64)     @ assignment.app.main(app.java:34)     @ helper.helperfunctions.saveparty(helperfunctions.java:24)     @ services.partyoperations.registerparty(partyoperations.java:53)     @ assignment.app.main(app.java:28) caused by: java.io.notserializableexception: models.registerparty     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1183)     @ java.io.objectoutputstream.writeobject(objectoutputstream.java:347)     @ helper.helperfunctions.saveparty(helperfunctions.java:20)     @ services.partyoperations.registerparty(partyoperations.java:52)     ... 1 more 

registerparty implements serializable interface. menu based app, when save object in file, save successfully. call method object in list, throw exception. idea why?

this method execute serialize object:

public void saveparty(registerparty registerparty){     try {         fileoutputstream fout = new fileoutputstream("/media/user/disk2/myapp/assignment/party.txt");         objectoutputstream oos = new objectoutputstream(fout);         oos.writeobject(registerparty);         oos.close();         system.out.println("successfull register");         system.out.println("========select choice========");         app.main(str);     }     catch (exception ex){             ex.printstacktrace();     } } 

when implement serializable object add static variable serialversionuid class:

private static final long serialversionuid = -1892561327013038124l; 

this line gets added suggestion either eclipse or android studio. don't know how intellijidea.

it worth try! believe id used deserialisation.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -