• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Serializable

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Dear all,

When i run this code, i am getting
java.io.NotSerializableException: java.io.FileOutputStream

Why this exception is thrown?? Even after going through the API i can't clearly understand the problem.

Please help me regarding this.
Thank you very much.
Regards,
Vijay
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your Tree class implement Serializable interface ?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, no, the problem is that you are trying to serialise the FileOutputStream, fs. You should be trying to serialise the Forest, f.

The exception message told you that: it said that FileOutputStream was not Serializable, which it isn't!

Rahul is right to say that Tree needs to be Serializable, but that's not the cause of the exception you are currently getting.

By the way, this is an example of why you should not use short, meaningless identifiers like "f" and "fs" for your variables. If they were called "forest" and "fileStream", I bet you'd have spotted the problem. We're not writing FORTRAN-66 - you can have meaningful identifiers in Java.
[ July 26, 2007: Message edited by: Peter Chase ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:
Um, no, the problem is that you are trying to serialise the FileOutputStream, fs. You should be trying to serialise the Forest, f.

Yes , I did not notice.

My bad.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic