Kryonet Registering Classes

I’m pretty deep into my project at this point, yet I’ve come across an issue with registering a class.


Mon Mar 03 10:22:00 EST 2014 ERROR:java.lang.IllegalArgumentException: Class is not registered: org.newdawn.slick.Animation$Frame
Note: To register this class use: kryo.register(org.newdawn.slick.Animation$Frame.class);

When I attempt to register: Serializer.register(org.newdawn.slick.Animation$Frame.class); I have the following syntax error: cannot be referenced using its binary name.

I realize there is something wrong with the ‘$’ character and Frame, yet I don’t know what to do. I’ve tried registering just register(org.newdawn.slick.Animation.class); yet the issue still remains.

Additional Information:
The new Packet I’ve created contains a SpriteSheet and Animation variable.

Any thoughts on this?!
Thanks.

Hmmm.
From what I think I remember, $ means that the class file has been created from another class file. What I mean is that you probably cannot register classes that are within other classes. You need to specify a class that has it’s own file and is not within other class.

That is interesting and I’ll obviously be investigating this further… If anyone has any insights, please feel open to share 8)

Here is a short example.

Animation.java

public class Animation {
		
		public static class Frame {
			
		}
	}

I’m guessing this is how you got it setup.

Just take Frame and put it into it’s own .java file.

Animation.java

public class Animation {
		
	}

Frame.java

public class Frame {
		
	}

$ indicates an internal class nested in another one. You probably only register Animation, but you need to register both Animation and Animation.Frame.

That is how I have my Packet infrastructure set up, not really the bug though.


public class Packet {

        public static class Packet1 {

            // ...

        }

        public static class Packet2 {

            // ...

        }
}

and I register via


Kryo Serializer = client.getKryo();
Serializer.register(Packet.Packet1.class);
Serializer.register(Packet.Packet2.class);

My issue comes about from code inside one of my packets. I have an object, Player, which has always been able to exist as a local variable of Packet1 (lets say)


public class Packet {

        public static class Packet1 {

            Player p = new Player();
            
            // not shown: get & set function for object p

        }

Recently I have added another object, which exists in Player


public class Player() {

        Spell s = new Spell();

            // not shown: get & set function for object s and initialization steps
}

Inside Spell:


public class Spell implements DrawableObject {

        public Animation animation = null;  //  object from: org.newdawn.slick.Animation
        public SpriteSheet sprite_sheet = null;  // object from: org.newdawn.slick.SpriteSheet

            // not shown: get & set function for objects and initialization steps

}

Here is the full trace:


Exception in thread "Client" com.esotericsoftware.kryo.KryoException: Encountered unregistered class ID: 7709
Serialization trace:
animation (spells.Spell)
MySpells (client_framework.Player)
p1 (client_framework.Team)
Team1 (client_framework.GameLobby)
G (client_framework.Packet$Packet2PlayerInit)
	at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:623)
	at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:747)
	at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.read(DefaultArraySerializers.java:340)
	at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.read(DefaultArraySerializers.java:293)
	at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:671)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:224)
	at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:760)
	at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.read(DefaultArraySerializers.java:340)
	at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.read(DefaultArraySerializers.java:293)
	at com.esotericsoftware.kryo.Kryo.readObjectOrNull(Kryo.java:732)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:229)
	at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:671)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:224)
	at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:671)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:224)
	at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:671)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:224)
	at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:760)
	at com.esotericsoftware.kryonet.KryoSerialization.read(KryoSerialization.java:57)
	at com.esotericsoftware.kryonet.TcpConnection.readObject(TcpConnection.java:137)
	at com.esotericsoftware.kryonet.Client.update(Client.java:239)
	at com.esotericsoftware.kryonet.Client.run(Client.java:317)
	at java.lang.Thread.run(Unknown Source)

The compiler gets hung up at the variable ‘animation’ located in Spell.java due to it being incorrectly registered (or something along those lines).

I thought what agentd said, yet for whatever reason I don’t know how to find the accurate path in registering Animation.Frame

This is not recognized:


Serializer.register(org.newdawn.slick.Animation.Frame.class);  // illegal, does not exist?

Thank you for your time.

I’m not sure you can serialize Slick internal classes with kryo just like that. like for example every class used by kryo needs an empty constructor too right ? but if you just use the lib as a jar you cannot implement that anyway
also imo you shouldnt save more to file than necessary but thats another discussion…