GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Regarding Serializable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regarding Serializable" Watch "Regarding Serializable" New topic
Author

Regarding Serializable

Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178


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

Joined: Nov 29, 2005
Posts: 2308
Does your Tree class implement Serializable interface ?


Rahul Bhattacharjee
LinkedIn - Blog
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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 ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Serializable