Serailization vs. Orgranization Problem

My program was working fine. However when I reoganized the message classes for networking into a seperate package under the main package the program started throwing ‘class not serializable’ errors at run time. Still compiles fine. Any thoughts on how to fix this problem.

The code looks fine from here. As does the exception.

ie: need more input… code, stack traces… anything would be more useful than “it doesn’t work.”

My Error is…

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main] java.lang.IllegalArgumentException: Class is not marked @Serializable:class Eden.Messages.Message_Hello at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:213) at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:151) at Eden.Client.Network_Controller.<init>(Network_Controller.java:17) at Eden.Client.EdenClient.simpleInitApp(EdenClient.java:33) at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225) at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130) at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207) at java.lang.Thread.run(Thread.java:724)

[java]
package Eden.Messages;

import com.jme3.network.AbstractMessage;

public class Message_Hello extends AbstractMessage
{
public boolean Offline_Mode = false;
public String Username = “”;

public Message_Hello()
{
    
}

public Message_Hello(String myUsername)
{
    Offline_Mode    = true;
    Username        = "";
}        

}
[/java]

[java]

package Eden.Client;

import Eden.Messages.Message_Accept;
import Eden.Messages.Message_Hello;
import Eden.Messages.Message_Reject;
import com.jme3.network.Client;
import com.jme3.network.ClientStateListener;
import com.jme3.network.Message;
import com.jme3.network.MessageListener;
import com.jme3.network.serializing.Serializer;

public class Network_Controller implements MessageListener<Client>,
ClientStateListener
{
public Network_Controller()
{
Serializer.registerClass(Message_Hello.class);
Serializer.registerClass(Message_Accept.class);
Serializer.registerClass(Message_Reject.class);

  }


  public void messageReceived(Client source, Message message) 
  {
      
  }
  
 @Override
  public void clientConnected(Client c) 
  {
     
  }
 
 @Override
  public void clientDisconnected(Client c, 
                                    ClientStateListener.DisconnectInfo info) 
  {
     
  }

}
[/java]

Again, this was working fine. Only thing I changed was I moved the message from package Eden to Eden.Messages

@Zarium said: Again, this was working fine. Only thing I changed was I moved the message from package Eden to Eden.Messages

That can’t be the only thing that changed. Your previous case must have had the @Serializable that this one doesn’t. You would have gotten the same error otherwise.

Is there a way we can somehow make this error message clearer?
“java.lang.IllegalArgumentException: Class is not marked @Serializable:class Eden.Messages.Message_Hello”

I found the solution, just took some digging and guess work.
The solution was to change the class header like so:

[java]
import com.jme3.network.AbstractMessage;
import com.jme3.network.serializing.Serializable;

@Serializable
public class Message_Hello extends AbstractMessage
{

[/java]

Seems simple in hind site. I had already tried with the java.io.Serializable import but the compiler didnt accept that as an annotation. I had to use the one from the JME network lib’s. I would still like to know why it was working before without the @Serializable annotation then suddenly stopped working. No answer for that one yet. Note, the spider monkey tutorials DO NOT use the annotation.

It would never have worked without that annotation. It’s just not possible. You must have had it before and somehow removed it… or were using different classes or something. You have to go through some tricks to get Serializer to deal with a class without this.

Which tutorial were you looking at?

Annotated screen shot from the tutorial linked from the tutorials page:

This tutorial:https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:networking