Im trying to create a multiplayer game using the networking library kryonet and I got the connection and sending strings to work but, now Im trying to send objects. What I want to do is send an array list but it gives me this error. I also tried to send just 1 object and it gave me the same error.
Exception in thread "Client" com.esotericsoftware.kryonet.KryoNetException: Error during deserialization.
at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:141)
at com.esotericsoftware.kryonet.Client.update(Client.java:247)
at com.esotericsoftware.kryonet.Client.run(Client.java:333)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): com.connorbrezinsky.spaceraiders.objects.Metor
at com.esotericsoftware.kryo.Kryo.newInstantiator(Kryo.java:1048)
at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1060)
at com.esotericsoftware.kryo.serializers.FieldSerializer.create(FieldSerializer.java:228)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:217)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:735)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:109)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:18)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:735)
at com.esotericsoftware.kryonet.KryoSerialization.read(KryoSerialization.java:58)
at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:139)
... 3 more
I tried creating a constructor with no args in the Metor class but that also didn't work
Exception in thread "Client" com.esotericsoftware.kryonet.KryoNetException: Error during deserialization.
at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:141)
at com.esotericsoftware.kryonet.Client.update(Client.java:247)
at com.esotericsoftware.kryonet.Client.run(Client.java:333)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.esotericsoftware.kryo.KryoException: java.lang.IllegalArgumentException: Can not set org.newdawn.slick.geom.Shape field com.connorbrezinsky.spaceraiders.objects.Object.s to java.lang.Float
Serialization trace:
s (com.connorbrezinsky.spaceraiders.objects.Metor)
metors (com.connorbrezinsky.spaceraiders.main.Response)
at com.esotericsoftware.kryo.serializers.FieldSerializer$ObjectField.read(FieldSerializer.java:626)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:221)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:735)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:109)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:18)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:654)
at com.esotericsoftware.kryo.serializers.FieldSerializer$ObjectField.read(FieldSerializer.java:605)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:221)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:735)
at com.esotericsoftware.kryonet.KryoSerialization.read(KryoSerialization.java:58)
at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:139)
... 3 more
Caused by: java.lang.IllegalArgumentException: Can not set org.newdawn.slick.geom.Shape field com.connorbrezinsky.spaceraiders.objects.Object.s to java.lang.Float
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at com.esotericsoftware.kryo.serializers.FieldSerializer$ObjectField.read(FieldSerializer.java:619)
... 13 more
Heres the client code
Kryo kryo = client.getKryo();
kryo.register(Request.class);
kryo.register(Response.class);
kryo.register(java.util.ArrayList.class);
kryo.register(Metor.class);
client.start();
try {
client.connect(10000, "192.168.1.130", 54555);
} catch (Exception er) {
er.printStackTrace();
}
Request request = new Request();
request.text="map_metor";
client.sendTCP(request);
client.addListener(new Listener() {
public void received(Connection connection, Object object) {
Response response = (Response) object;
System.out.println(response.metors);
}
});
Heres the server code
public static Server server;
public static World world;
public static final int PORT = 54555;
public static void main(String[] args) throws IOException {
System.out.println("Starting server...");
server = new Server();
world = new World(2000,2000);
Kryo kryo = server.getKryo();
kryo.register(Request.class);
kryo.register(Response.class);
kryo.register(java.util.ArrayList.class);
kryo.register(Metor.class);
server.start();
server.bind(54555);
System.out.println("Server started, generating world");
world.setMaxMetors(20);
world.setMaxPlanets(10);
world.generateObjects();
server.addListener(new Listener() {
public void received(Connection connection, Object object) {
if (object instanceof Request) {
Request request = (Request) object;
System.out.println(request.text);
if (request.text.equalsIgnoreCase("map_metor")) {
Response response = new Response();
response.metors = world.metors;
connection.sendTCP(response);
}else if(request.text.equalsIgnoreCase("map_planets")) {
Response response = new Response();
response.planets = world.planets;
connection.sendTCP(response);
}
}
}
});
}
Sorry for the long post, but this just seems to be a weird issue unless Im totally oblivious to something.
EDIT: So I've come to the conclusion Kryonet has issues serializing the slick2d Image class or there is different conflict with Kryonet & slick2d.
you have to make sure you have all of the same variables in your classes that you send over with kryonet.