Jump to content

Objectstream error

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
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


#2
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts
Possible could you provide the half baked code or is that what you want to do?
Posted Image

#3
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
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.

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
Ah yes, it works now. Thanks a lot.