This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
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
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
wood burning stoves
 
subject: Only new Instance of object is serializable?
 
Similar Threads
write/read two byte arrays to single file- please help!
Custom zip file- Object storage
How the objects are constructed at the time of de-serialization?
java.sql.SQLException: ORA-01407:
Java class consisting of serialVersionUID