好的伙计们,我正在libgdx中制作一个角色编辑器,它基本上是动画命中箱的编辑器,到目前为止它起作用,它保存了一个json文件,但每当我点击加载时,它就会崩溃。
我知道错误是指libgdx.texture不包含0参数构造函数,但我想知道我该怎么做。
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Class cannot be created (missing no-arg constructor): com.badlogic.gdx.graphics.Texture
Serialization trace:
keyTable (com.badlogic.gdx.utils.ObjectSet)
textures (com.badlogic.gdx.graphics.g2d.TextureAtlas)
atlas (hitbox.Animations)
animation_list (hitbox.Character)
这是我的代码:
public void Save(String s)
{
Json json = new Json();
String character_string = json.toJson(character);
FileHandle file = Gdx.files.absolute(s);
file.writeString(character_string, false);
}
public void Load(String s)
{
FileHandle file = Gdx.files.absolute(s);
if (file.exists())
{
String character_string = file.readString();
Json json = new Json();
character = json.fromJson(Character.class, character_string);
}
}
public class Character {
public List<Animations> animation_list;
public Character()
{
animation_list = new ArrayList<Animations>();
animation_list.add(new Animations());
}
}
public class Animations {
public List<Frame> frame;
public String name_of_animation, path_to_atlas;
public int index, last_frame, number_frames;
public TextureAtlas atlas;
public Animation animation;
//"data/ATHENA/walking.atlas" path to atlas
public Animations()
{
frame = new ArrayList<Frame>();
frame.add(new Frame());
name_of_animation = "null name";
path_to_atlas = "null path";
index = 0;
last_frame = 0;
number_frames = 0;
}
public void AddAtlas(String name)
{
FileHandle handle = Gdx.files.absolute(name);
if (handle.exists())
{
atlas = new TextureAtlas(handle);
animation = new Animation(1/15f, atlas.getRegions());
}
}
}