SpiderMonkey ClassCastException Error: SerializerRegistrationsMessage [Solved]

I’ve just started using a more recent version of JME (3.1), and for some reason my SpiderMonkey networking code has decided to stop working with the error

java.lang.ClassCastException: com.jme3.network.message.SerializerRegistrationsMessage$Registration cannot be cast to com.jme3.network.Message

which is technically correct since Registration is unrelated to Message. I assume these are built-in “behind the scenes” classes and messages in order for SpiderMonkey to set itself up, but I’ve no idea what to try next to get it working.

I’ve followed the SpiderMonkey tutorial at https://jmonkeyengine.github.io/wiki/jme3/advanced/networking.html. I’ve also tried not registering the serialization on the client, as per the comments at the top of SerializerRegistrationsMessage.java, but this just gave me the error “Class has not been registered”.

Has anyone else had this problem?

Your code looks fine from here.

If you want to see some working examples then you can look here:

network-basic may be the closest to what you need. sim-eth-basic and sim-eth-es are fully working demos with synchronization, etc… network-basic is just a basic client/server setup with basic UI for connecting.

I’ll create a minimal example. I’ve also just found this thread which seems to have a few suggestions.

I’ve managed to fix this (it seems) by only sending from the client once it has received a message from the server.