• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding Serializable

 
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your Tree class implement Serializable interface ?
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Whatever you say buddy! And I believe this tiny ad too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic