I am currently setting up a client and a server.
When I run the server I get the following error:
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.RuntimeException: Registration error: no-argument constructor not found on:class mygame.Net$serverIdMessage
at com.jme3.network.serializing.serializers.FieldSerializer.checkClass(FieldSerializer.java:59)
at com.jme3.network.serializing.serializers.FieldSerializer.initialize(FieldSerializer.java:65)
at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:175)
at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:141)
at mygame.Net.startWorldServer(Net.java:49)
at mygame.Main.simpleInitApp(Main.java:49)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:231)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
at java.lang.Thread.run(Thread.java:722)
Below is my class I am serializing. (It works fine on my client app but bombs on my server app) Any thoughts?
@Serializable
public class serverIdMessage extends AbstractMessage {
private String ip;
private int port;
private String name;
private String version;
public serverIdMessage() {} // empty constructor
public serverIdMessage(String ip1, int port1,String name1, String version1) {
ip=ip1;
port=port1;
name=name1;
version=version1;
} // custom constructor
}
What’s AbstractMessage? Does it not have a default constructor?
It is one of the JME3 imports for networking
import com.jme3.network.AbstractMessage;
isnt ít wrong that it looks for mygame.Net$serverIdMessage
instead of mygame.serverIdMessage?
Seems like your trying to create a new object called Net$serverIdMessage instead of the one you want serverIdMessage
Below is my class. I am calling it from the init in the Main
[java]import java.util.logging.Logger;
/**
*
-
@author Tim
*/
public class Net {
//used to define structure of data being transmitted
@Serializable
public class serverIdMessage extends AbstractMessage {
private String ip;
private int port;
private String name;
private String version;
public serverIdMessage() {} // empty constructor
public serverIdMessage(String ip1, int port1,String name1, String version1) {
ip=ip1;
port=port1;
name=name1;
version=version1;
} // custom constructor
}
public void startWorldServer(String ip, int port){
try {
Server worldServer = Network.createServer(port);
worldServer.start();
Serializer.registerClass(serverIdMessage.class);
worldServer.addMessageListener(new ServerListener(), serverIdMessage.class);
} catch (IOException ex) {
Logger.getLogger(Net.class.getName()).log(Level.SEVERE, null, ex);
}
}
public class ServerListener implements MessageListener<HostedConnection> {
public void messageReceived(HostedConnection source, Message message) {
if (message instanceof serverIdMessage) {
// do something with the message
serverIdMessage rcvServerConnectionMsg = (serverIdMessage) message;
System.out.println(“Server received '” +rcvServerConnectionMsg.name +"’ from client #"+source.getId() );
} else {
System.out.println(“Nothing yet…” );
}
}
}
}[/java]
Put your inner class in separate folders and remove public serverIdMessage() {} // empty constructor
as its not needed.
According to the tutorials I thought it was needed?
Nah, I have them all in separate files. I think it’s a matter of cleanliness as, when compiled, would still end up in separate files.
But It’s easier to debug if you have separate files.
Seems to work having it in a separate file. Odd that it works in the same file for the client and not the server? Oh well, at least my code will be cleaner this way.
Thanks for your help.
I think it has to do with your class setup:
[java] @Serializable
public class serverIdMessage extends AbstractMessage {[/java]
The serializable is read as part of your Net class not your following class serverIdMessage.
That might have been the problem, but good that it works now
The reason that it didn’t work as an inner class is because the class wasn’t static. Non-static inner classes must be instantiated as children of an instance of the outer class… so SpiderMonkey can’t do it.
SpiderMonkey must be able to call new YourClass()… and it couldn’t have done that for a non-static inner class. For example, to instantiate your class externally, you’d have to do something like:
Net net = new Net();
Message msg = new net.serverIdMessage();
It’s just weird.