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)
> 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...
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
I usually prefer HashMaps to Hashtables. While I've never tried to
serialize the latter, I have serialized the former without problem.
Brian