Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Objectstream error

stream

  • Please log in to reply
3 replies to this topic

#1 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 01 July 2009 - 02:01 AM

Hello, i'm making a simple thing to save a class i've made to a .dat-file using objectoutputstream and writeObject(myClass).

It never wanted to write it correctly. After adding a lot of catches it turns out to be a "NotSerializableException", which means : Some object to be serialized does not implement the java.io.Serializable interface. Thrown when an instance is required to have a Serializable interface.

Could somebody explain that error in common english? :P What does it mean? (and how can i solve it)

Seems like it's trown when the class i want to write contains a variable that is of a type NonSerializableObject.. whatever that means.

the class i'm writing has these attributes:
private StockSubClass[] cds;
the stocksubclass contains these:
class StockSubClass extends Stock implements Comparable
    {

     private String CdGenre;
and Stock has:
class Stock {

    private String cdArtist;
    private int cdItem;
    private int cdUnits;
    private double cdPrice;

Edited by wim DC, 01 July 2009 - 02:08 AM.
typo

  • 0

#2 Turk4n

Turk4n

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 01 July 2009 - 09:21 PM

Possible could you provide the half baked code or is that what you want to do?
  • 0

#3 Sinipull

Sinipull

    CC Addict

  • Validating
  • PipPipPipPipPip
  • 384 posts

Posted 02 July 2009 - 02:44 PM

Every object you want to serialize needs to implement "Serializable" object.
So adding "implements Serializable" to the class header should fix it...

in your case
class Stock implements Serializable

i think every class extended from Stock, will also be Serializable, so there is no need to write it twice.
  • 0

#4 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 03 July 2009 - 12:15 AM

Ah yes, it works now. Thanks a lot.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download