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
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.
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...