使用libgdx的默认外观.. SerializationException:读取文件时出错:ui / uiskin.json

时间:2015-07-10 16:44:19

标签: java libgdx

我正在尝试运行我的LibGDX项目的桌面版,但收到以下错误..

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: ui/uiskin.json
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:97)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:74)
    at com.mygdx.game.MainMenu.show(MainMenu.java:51)
    at com.badlogic.gdx.Game.setScreen(Game.java:61)
    at com.mygdx.game.Splash$1.run(Splash.java:48)
    at com.badlogic.gdx.scenes.scene2d.actions.RunnableAction.run(RunnableAction.java:42)
    at com.badlogic.gdx.scenes.scene2d.actions.RunnableAction.act(RunnableAction.java:32)
    at com.badlogic.gdx.scenes.scene2d.actions.SequenceAction.act(SequenceAction.java:65)
    at com.badlogic.gdx.scenes.scene2d.Actor.act(Actor.java:95)
    at com.badlogic.gdx.scenes.scene2d.Group.act(Group.java:49)
    at com.badlogic.gdx.scenes.scene2d.Stage.act(Stage.java:223)
    at com.badlogic.gdx.scenes.scene2d.Stage.act(Stage.java:186)
    at com.mygdx.game.Splash.render(Splash.java:29)
    at com.badlogic.gdx.Game.render(Game.java:46)
    at com.mygdx.game.ColorCatch.render(ColorCatch.java:19)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:215)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: ui/uiskin.json
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:683)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:95)
    ... 16 more
Caused by: com.badlogic.gdx.utils.SerializationException: 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:416)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:410)
    at com.badlogic.gdx.utils.Json.readValue(Json.java:867)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:404)
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:681)
    ... 17 more
Caused by: com.badlogic.gdx.utils.reflect.ReflectionException: Class not found: com.badlogic.gdx.scenes.scene2d.ui.Tooltip$TooltipStyle
    at com.badlogic.gdx.utils.reflect.ClassReflection.forName(ClassReflection.java:30)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:414)
    ... 21 more
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.scenes.scene2d.ui.Tooltip$TooltipStyle
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:191)
    at com.badlogic.gdx.utils.reflect.ClassReflection.forName(ClassReflection.java:28)

项目结构如下..

rob@work:~/git/test$ ls
android       core     gradle             gradlew      ios   local.properties
build.gradle  desktop  gradle.properties  gradlew.bat  libs  settings.gradle
rob@work:~/git/test$ ls android/assets/ui/
default.fnt   uiskin.atlas   uiskin.json   uiskin.png

简化版MainMenu ..

public class MainMenu implements Screen {

    private Stage stage = new Stage();
    private TextureAtlas atlas;
    private Skin skin;
    private Button quit;

    public MainMenu() {}

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        stage.act(delta);
        stage.draw();
    }

    @Override
    public void show() {

        atlas = new TextureAtlas("ui/uiskin.atlas");
        skin = new Skin(Gdx.files.internal("ui/uiskin.json"));
        skin.addRegions(atlas);
    }

    @Override
    public void resize(int width, int height) {

        TextButtonStyle styleQuit = new TextButtonStyle();
        styleQuit.up = skin.getDrawable("8layer");
    }
}

2 个答案:

答案 0 :(得分:1)

您是否将libgdx更新为1.6.4版?刚刚添加了工具提示,如果您的皮肤文件丢失,它将崩溃。检查libgdx repo中的测试,看看它是什么样的。

答案 1 :(得分:0)

检查您的uiskin.atlas文件。可能它不包含Tooltip的任何定义。只需从uiskin.json中删除com.badlogic.gdx.scenes.scene2d.ui.Tooltip$TooltipStyle的块并进行测试即可。我相信这是造成这个问题的原因。如果您没有使用任何工具提示,那么您可以永久地从json中删除该块并使用它。它应该工作。如果需要,则必须在atlas文件中添加工具提示所需的条目。