Hashtable sessions for Android
I am having a weird problem with serializing a Hashtable. I have created a Server, Client application. Where server (PC / MAC) serializes Hashtable and sends it to client (Android) over UDP. The data is being sent / read correctly, but I am getting a bunch of these messages below in the LogCat.
04-12 11:19: 43.059: DEBUG / dalvikvm (407): GetFieldID: Unable to find field Ljava / util / Hashtable; .loadFactor: F
Sometimes I saw these
04-12 11: 21: 19.150: DEBUG / dalvikvm (407): GC freed 10814 objects / 447184 bytes in 97ms
The app will run for 2-3 minutes and then crash. Interestingly, I don't see any Loadfactor errors on SDK 1.5. But I see GC Free xxxx objects that are often quiet.
After debugging, I found that the problem is with de-serialization and the error / warning comes from the following code
code:
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bis);
object = ois.readObject();
in Code:
object = ois.readObject();
on the client. My server serializes code like this.
code:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
Any idea what's going on?
Thanks for the help!
a source to share
Too late, but for anyone else who comes across this:
Noting what was said above (don't say you weren't warned):
I have dealt with this using protocol libraries and using maps with long objects. I understand that if dalvik or Java changes the serialization I'm full, but serialization is much easier than the alternatives, and that the error message (while benign) means a lot of unnecessary allocations and overhead. Also, I am using proguard to reduce the library to 45K (out of ~ 1M) which I need. I'd also like to suggest that you keep a copy of the trove source code in case they change their serialization, and also note that I need 3.0.0 rc1 to get it working (not sure if the serialid necessarily matches between versions).
a source to share