I'm trying to serialize a Hashtable consisting of objects
belonging to a class defined by me. For example, I have a .java file
with two class definitions: classA & classB. classA has the main()
function and in it, I create objects of classB and store them in a
Hashtable. Then, I use the writeObject function (of the
ObjectOutputStream class) to write the Hashtable to a file. But, this
fails with the following error message:
Exception in thread "main" java.io.NotSerializableException: classB
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148,
Compiled Code)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366,
Compiled Code)
at java.util.Hashtable.writeObject(Hashtable.java:757,
Compiled Code)
at java.lang.reflect.Method.invoke(Native Method)
at java.io.ObjectOutputStream.invokeObjectWriter(ObjectOutputStream.java:1878,
Compiled Code)
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1210,
Compiled Code)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366,
Compiled Code)
at convert.main(convert.java:20, Compiled Code)
The Java1.3 API documentation seems to indicate that the Hashtable
class implements the Serializable interface, but does it also require
that the elements of the Hashtable implement the Serializable
interface?
Can somebody please give me some pointers to solve this problem?
Thanx in advance,
Swaroop