我试图让一个简单的客户端/服务器类进行通信,以便以后用于实现我的MP游戏。问题是当我执行Unable to create serializer
时,我收到此new Client()
异常,这个问题显然可能是因为ASM库已从Kryonet jar中过时。
好吧,我去做了那个:更新库。我仍然得到错误。我继续尝试https://groups.google.com/forum/#!topic/kryonet-users/D5ssaQyWeR4
建议的解决方案但它还没有工作......
我对这些想法感到茫然,在线解决方案与我尝试过的解决方案不同,并且严重浪费我的时间来处理这个错误。真的需要通过这个扩大到我的游戏。以下是错误:
Exception in thread "main" java.lang.IllegalArgumentException: Unable to create serializer "com.esotericsoftware.kryo.serializers.FieldSerializer" for class: com.esotericsoftware.kryonet.FrameworkMessage$RegisterTCP
at com.esotericsoftware.kryo.Kryo.newSerializer(Kryo.java:337)
at com.esotericsoftware.kryo.Kryo.newDefaultSerializer(Kryo.java:316)
at com.esotericsoftware.kryo.Kryo.getDefaultSerializer(Kryo.java:309)
at com.esotericsoftware.kryo.Kryo.register(Kryo.java:353)
at com.esotericsoftware.kryonet.KryoSerialization.<init>(KryoSerialization.java:33)
at com.esotericsoftware.kryonet.KryoSerialization.<init>(KryoSerialization.java:25)
at com.esotericsoftware.kryonet.Client.<init>(Client.java:75)
at com.esotericsoftware.kryonet.Client.<init>(Client.java:57)
at gamep2.net.client.GameClient.<init>(GameClient.java:30)
at gamep2.net.client.GameClient.main(GameClient.java:55)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.esotericsoftware.kryo.Kryo.newSerializer(Kryo.java:324)
... 9 more
Caused by: java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.MethodVisitor, but class was expected
at com.esotericsoftware.reflectasm.FieldAccess.insertConstructor(FieldAccess.java:144)
at com.esotericsoftware.reflectasm.FieldAccess.get(FieldAccess.java:109)
at com.esotericsoftware.kryo.serializers.FieldSerializer.rebuildCachedFields(FieldSerializer.java:104)
at com.esotericsoftware.kryo.serializers.FieldSerializer.<init>(FieldSerializer.java:50)
... 14 more
现在,这是一个简单的Client类:
public class GameClient extends Thread{
public Client client;
public GameClient() throws IOException{
this.client = new Client();
this.register();
NetworkListener netList = new NetworkListener();
netList.init(client);
client.addListener(netList);
client.start();
Log.info("[CLIENT] Attempting to connect...");
client.connect(5000, "192.168.1.13", 54556);
}
public void register(){
Kryo kryo = client.getKryo();
kryo.register(Packet0LoginRequest.class);
kryo.register(Packet1LoginAnswer.class);
kryo.register(Packet2Message.class);
}
}
现在是Server类:
public class Start {
private static Server server;
private int port = 54556;
public Start() throws IOException{
server = new Server();
registerPackets();
server.addListener(new NetworkListener());
server.bind(port);
server.start();
System.out.println("Port: " + port);
System.out.println("Starting server...");
}
private void registerPackets(){
Kryo kryo = server.getKryo();
kryo.register(Packet0LoginRequest.class);
kryo.register(Packet1LoginAnswer.class);
kryo.register(Packet2Message.class);
}
public static void main(String[] args){
try {
new Start();
Log.set(Log.LEVEL_DEBUG);
} catch (IOException e) {
e.printStackTrace();
}
}
}