com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): android.content.ComponentName

2,750 views
Skip to first unread message

Ramin Heidari

unread,
May 30, 2012, 6:13:58 AM5/30/12
to kryo-users
Hi,

I'm trying to serialize android intent and send it through socket to
server and deserialize it on the server by kryo but im getting
exception on server side during deserialization .I'd appritiate if you
help to know how i can fix it.

Server Side code :
Kryo kryo = new Kryo();

Input input = new Input(client.getInputStream());
Intent intent =new Intent();
intent = kryo.readObject(input, Intent.class);
input.close();


Client side code:
Output output = new Output(socket.getOutputStream());

Kryo kryo = new Kryo();
kryo.register(Intent.class);

Intent intent = new Intent(ClientActivity.this, MyService.class);
kryo.writeObject(output, intent);
output.close();

Exception :

05-30 10:08:30.894: W/System.err(8276):
com.esotericsoftware.kryo.KryoException: Class cannot be created
(missing no-arg constructor): android.content.ComponentName
05-30 10:08:30.894: W/System.err(8276): Serialization trace:
05-30 10:08:30.894: W/System.err(8276): mComponent
(android.content.Intent)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Kryo.newInstantiator(Kryo.java:1001)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1013)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Serializer.create(Serializer.java:27)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Kryo.readObjectOrNull(Kryo.java:694)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:
229)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:614)
05-30 10:08:30.894: W/System.err(8276): at
com.myapp.socket.ServerActivity$ServerThread.run(ServerActivity.java:
167)
05-30 10:08:30.894: W/System.err(8276): at
java.lang.Thread.run(Thread.java:856)
05-30 10:08:30.894: W/System.err(8276):
com.esotericsoftware.kryo.KryoException: Class cannot be created
(missing no-arg constructor): android.content.ComponentName
05-30 10:08:30.894: W/System.err(8276): Serialization trace:
05-30 10:08:30.894: W/System.err(8276): mComponent
(android.content.Intent)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Kryo.newInstantiator(Kryo.java:1001)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1013)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Serializer.create(Serializer.java:27)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Kryo.readObjectOrNull(Kryo.java:694)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:
229)
05-30 10:08:30.894: W/System.err(8276): at
com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:614)
05-30 10:08:30.894: W/System.err(8276): at
com.myapp.socket.ServerActivity$ServerThread.run(ServerActivity.java:
167)
05-30 10:08:30.894: W/System.err(8276): at
java.lang.Thread.run(Thread.java:856)


Nate

unread,
May 30, 2012, 1:22:34 PM5/30/12
to kryo-...@googlegroups.com
ComponentName can't be created, has no zero arg constructor. Write a serializer for it.

-Nate




--
You received this message because you are subscribed to the "kryo-users" group.
http://groups.google.com/group/kryo-users

Martin Grotzke

unread,
May 30, 2012, 2:13:55 PM5/30/12
to kryo-...@googlegroups.com

Shouldn't such a case be handled by objenesis?

Cheers,
Martin

Nate

unread,
Jun 1, 2012, 4:46:52 AM6/1/12
to kryo-...@googlegroups.com
Objenesis isn't enabled by default. It should only be used for classes designed to be used without calling a constructor or known to work when created that way, so it should be a conscious decision to enable. I haven't looked at an Android Intent closely enough to see how it could be serialized. I know it has its own serialization mechanism since its purpose is interprocess communication.

-Nate
Reply all
Reply to author
Forward
0 new messages