InvalidClassException while serializing

Discussion in 'Java' started by Dave Rudolf, Dec 20, 2003.

  1. Dave Rudolf

    Dave Rudolf Guest

    Hi all,

    I have a class that implements Serializable, but also inherits from an
    abstract (and non-serializable) class. For some reason, when I try to write
    it to an ObjectOutputStream, it gives the following exception (sorry about
    the line wrapping):

    java.io.InvalidClassException: texdist.util.array2d.ObjectArray2D; no valid
    constructor
    at java.io_ObjectStreamClass.<init>(ObjectStreamClass.java:375)
    at java.io_ObjectStreamClass.lookup(ObjectStreamClass.java:249)
    at java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1010)
    at
    java.io_ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1330)
    at java.io_ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1302)
    at
    java.io_ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1245)
    at java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
    at java.io_ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
    at
    texdist.texture.morphogen.AbstractMorphogenLattice.cloneRaw(AbstractMorphoge
    nLattice.java:108)
    ....


    Can anyone tell me what it's complaining about? The top class two
    constructors: one has a couple of int params, the other has no params and
    just calls the two-int constructor with default values.

    Dave
    Dave Rudolf, Dec 20, 2003
    #1
    1. Advertising

  2. Dave Rudolf

    Sudsy Guest

    Dave Rudolf wrote:
    > Hi all,
    >
    > I have a class that implements Serializable, but also inherits from an
    > abstract (and non-serializable) class. For some reason, when I try to write
    > it to an ObjectOutputStream, it gives the following exception (sorry about
    > the line wrapping):

    <snip>
    > Can anyone tell me what it's complaining about? The top class two
    > constructors: one has a couple of int params, the other has no params and
    > just calls the two-int constructor with default values.
    >
    > Dave


    What about the subclass? If you specify any constructors at all then
    Java won't build you the default, no-argument constructor. And it
    looks like this is what's missing: the no-argument constructor.
    Sudsy, Dec 20, 2003
    #2
    1. Advertising

  3. Dave Rudolf

    Dave Rudolf Guest

    "Sudsy" <> wrote in message
    news:...
    > Dave Rudolf wrote:
    > > Hi all,
    > >
    > > I have a class that implements Serializable, but also inherits from an
    > > abstract (and non-serializable) class. For some reason, when I try to

    write
    > > it to an ObjectOutputStream, it gives the following exception (sorry

    about
    > > the line wrapping):

    > <snip>
    > > Can anyone tell me what it's complaining about? The top class two
    > > constructors: one has a couple of int params, the other has no params

    and
    > > just calls the two-int constructor with default values.
    > >
    > > Dave

    >
    > What about the subclass? If you specify any constructors at all then
    > Java won't build you the default, no-argument constructor. And it
    > looks like this is what's missing: the no-argument constructor.
    >


    Sorry, I mislead you in my last post. The subclass (which is also the only
    class that is being serialized) has a the default constructor, but some of
    the others up the hierarchy (that are not serializable) do not have a
    default.
    Dave Rudolf, Dec 20, 2003
    #3
  4. Dave Rudolf

    Sudsy Guest

    Dave Rudolf wrote:
    <snip>
    > Sorry, I mislead you in my last post. The subclass (which is also the only
    > class that is being serialized) has a the default constructor, but some of
    > the others up the hierarchy (that are not serializable) do not have a
    > default.


    PLEASE READ THE JAVADOCS!
    All the information you need is right there. I hate to waste bandwidth
    answering questions when the answers are so readily available.

    Follow this link:
    <http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html>

    Start reading here:
    "To allow subtypes of non-serializable classes to be serialized...
    Sudsy, Dec 20, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mario Rosario

    Help - java.io.InvalidClassException

    Mario Rosario, Sep 19, 2003, in forum: Java
    Replies:
    6
    Views:
    21,212
    SteveE
    Sep 24, 2003
  2. Aidan
    Replies:
    6
    Views:
    1,053
    Aidan
    Jun 4, 2004
  3. Nomak
    Replies:
    11
    Views:
    1,871
    Arnaud Berger
    Apr 18, 2005
  4. Raga

    InvalidClassException!

    Raga, Sep 26, 2006, in forum: Java
    Replies:
    10
    Views:
    4,408
    shweta.naik
    Aug 22, 2007
  5. Replies:
    1
    Views:
    366
    Manish Pandit
    Jun 18, 2007
Loading...

Share This Page