Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Only new Instance of object is serializable?

 
Ben Flowers
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic