File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Only new Instance of object is serializable? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Only new Instance of object is serializable?" Watch "Only new Instance of object is serializable?" New topic
Author

Only new Instance of object is serializable?

Ben Flowers
Greenhorn

Joined: Sep 12, 2011
Posts: 17
Hi Basicaly im trying to save my object to file, but im getting a NotSerializableException
However if i create a new object then it works fine.


the above code fails on the second line but the first runs?
Does anyone knwo why this is happening or how i can fix this?
Thanks,
Ben
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18370

Your old object probably has a field that is not serializable. When an object is serialized, all of its non-transient fields are also serialized, and therefore these must be serializable as well.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

And if you look at the error message more carefully, you will notice that it mentions the name of the class which was not serializable.
 
 
subject: Only new Instance of object is serializable?
 
Threads others viewed
Custom zip file- Object storage
Java class consisting of serialVersionUID
How the objects are constructed at the time of de-serialization?
write/read two byte arrays to single file- please help!
java.sql.SQLException: ORA-01407:
developer file tools