Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Serializing a Hashtable of objects

1 view
Skip to first unread message

Swaroop Kumar

unread,
Nov 14, 2001, 2:58:59 PM11/14/01
to
Hi:

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

Nils O. Selåsdal

unread,
Nov 14, 2001, 3:15:16 PM11/14/01
to
Yes it does, you are serializing the objects in the Hashtable, so those
objects must also be(implements) Serializable.
0 new messages