Error serializing message

Everytime I try to send a message to the server, I’ve got a runtimeexception saying ‘error serializing message’.How can i solve this?

You need to show us the actual exception… with root cause and everything. Otherwise, there are about half a dozen different things I could randomly guess it might be. :slight_smile:

INFO: Connection established, id:2.

17-jul-2011 23:20:23 com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.RuntimeException: Error serializing message

at com.jme3.network.base.MessageProtocol.messageToBuffer(MessageProtocol.java:82)

at com.jme3.network.base.DefaultClient.send(DefaultClient.java:213)

at com.jme3.network.base.DefaultClient.send(DefaultClient.java:193)

at mygame.Mplay.initConnection(Mplay.java:44)

at mygame.Main.simpleInitApp(Main.java:227)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:230)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:124)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:200)

at java.lang.Thread.run(Thread.java:662)

Caused by: java.io.IOException: The class messages.JoiningMessage is not registered in the serializer!

at com.jme3.network.serializing.serializers.FieldSerializer.writeObject(FieldSerializer.java:162)

at com.jme3.network.serializing.Serializer.writeClassAndObject(Serializer.java:368)

at com.jme3.network.base.MessageProtocol.messageToBuffer(MessageProtocol.java:74)

… 8 more

BUILD SUCCESSFUL (total time: 41 seconds)

That is because “The class messages.JoiningMessage is not registered in the serializer.”



So you have not registered your message class with Serializer. It doesn’t know how to serialize it.

Isn’t that done by writing ‘@Serializable’ at the beginning of your class(which I have done)? Or do i have to call a method to register them?

You have to call a method on Serializer to register them…



and… all classes must be registered in the exact same order on both client and server. So the recommended advice is to do this in a static method shared by client and server so as not to easily forget something.



Note: I believe that if you specify your own ID in @Serializable that it auto registers them on write… but you’d still have the problem of not knowing what class to instantiate at the other end of the connection. Registering a serializable class has the effect of giving it a “unique ID” that the server and client can use to resolve to the actual class. If the class hasn’t been registered then the side reading one of these IDs won’t know which class to instantiate.



It makes for very fast/tight network data but is kind of fragile if care is not taken to register the classes as outlined above. Someday I plan to rewrite it but so far it’s only a few moments of pain every now and then… and there are always bigger things to deal with it seems.

1 Like

thanks, I got it to work.