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

can't serialize hashtables

1 view
Skip to first unread message

T L Hardy

unread,
Jun 13, 2001, 5:13:42 PM6/13/01
to
I'm writing this java program on a rh linux system (6.2 i think). And so
everything's working fine, until I try to serialize a hashtable. I can
serialize everything else that I've tried (Vectors, Integers, Strings, my
custom classes), but when I try to readObject when it's a Hashtable, I get a
big long exception stack. ht2=(Hashtable)ois.readObject(); is the line that
the exception is thrown on.

I was wondering if this is because I'm using a weird blend of java (kaffe
that comes with Red Hat 6.2), or because I'm doing something wrong.
(Interestingly i tried serializing a LinkedList but i got a NotSerializable
exception... so maybe my librarys are just really old?)

Below is the code and the exception that I got.

Thanks,
Jon

Integer anInt = new Integer(2);
Hashtable ht = new Hashtable(10);
ht.put("Hi", anInt);

File f1 = new File("test");
FileOutputStream fos = new FileOutputStream(f1);
ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(v);
oos.flush();
oos.close();
fos.close();
Integer anInt2;
Hashtable ht2;
File f2 = new File("test");
FileInputStream fis = new FileInputStream(f2);
ObjectInputStream ois = new ObjectInputStream(fis);
ht2 = (Hashtable)ois.readObject();
ois.close();
fis.close();


java.lang.IllegalArgumentException
at java.lang.Throwable.<init>(Throwable.java:33)
at java.lang.Exception.<init>(Exception.java:20)
at java.lang.RuntimeException.<init>(RuntimeException.java:17)
at
java.lang.IllegalArgumentException.<init>(IllegalArgumentException.java:17)
at java.util.HashMap.<init>(HashMap.java:56)
at
java.util.Hashtable$DefaultSerialization.readDefaultObject(Hashtable.java:16
5)
at
kaffe.io.ObjectStreamClassImpl.defaultReadObject(ObjectStreamClassImpl.java:
340)
at
kaffe.io.ObjectInputStreamImpl.defaultReadObject(ObjectInputStreamImpl.java:
202)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:206)
at java.util.Hashtable.readObject(Hashtable.java:180)
at
kaffe.io.ObjectStreamClassImpl.getObjectWithoutSuper(ObjectStreamClassImpl.j
ava:81)
at kaffe.io.ObjectStreamClassImpl.getObject(ObjectStreamClassImpl.java:62)
at kaffe.io.ObjectInputStreamImpl.getObject(ObjectInputStreamImpl.java:237)
at
kaffe.io.ObjectInputStreamImpl.readObject(ObjectInputStreamImpl.java:161)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:194)


boruvek

unread,
Jun 13, 2001, 5:50:19 PM6/13/01
to
I have tried it on Sun JDK1.3, Windows and everything is ok...
(instead of this line

> oos.writeObject(v);

you mean

> oos.writeObject(h1);

am I right... :)


"T L Hardy" <tlh...@flash.net> píše v diskusním příspěvku
news:9g8l5k$icu$1...@newssvr05-en0.news.prodigy.com...

T L Hardy

unread,
Jun 13, 2001, 7:48:44 PM6/13/01
to
> (instead of this line
> > oos.writeObject(v);
> you mean
> > oos.writeObject(h1);
> am I right... :)

Yes, that's what I have in my real code, not the thing I copied to the
newsgroup. I guess it's my crappy version of java then... alas!

jon


Brian McKeever

unread,
Jun 13, 2001, 8:25:45 PM6/13/01
to
"T L Hardy" <tlh...@flash.net> wrote in message
news:9g8u7q$7mmk$1...@newssvr06-en0.news.prodigy.com...

I usually prefer HashMaps to Hashtables. While I've never tried to
serialize the latter, I have serialized the former without problem.

Brian


0 new messages