Android 加载时应用程序崩溃 uiskin.json

Android application crashes when loading uiskin.json

我在将 uiskin.json 文件加载到我的 Android 应用程序时遇到问题。 这是我写的一段测试代码:

private TextureAtlas buttonsAtlas;

private Skin skin;
private Skin buttonSkin;

private Stage stage;

private TextButton textButton;
private ImageButton imageButton;

@Override
public void create () {
    stage = new Stage();
    buttonsAtlas = new TextureAtlas(Gdx.files.internal("buttons.pack"));
    buttonSkin = new Skin(buttonsAtlas);

    skin = new Skin(Gdx.files.internal("uiskin.json"));
    textButton = new TextButton("test", skin);
    textButton.setPosition(Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 4);

    imageButton = new ImageButton(buttonSkin.getDrawable("imageUp"), buttonSkin.getDrawable("imageDown"));
    imageButton.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);

    stage.addActor(imageButton);
    stage.addActor(textButton);


    Gdx.input.setInputProcessor(stage);

}

@Override
public void render () {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
}

此代码在从桌面启动器启动时完美运行。但是,当导出 android 文件并将 APK 加载到模拟器中时(我使用的是 BlueStacks),程序就会崩溃。

当我评论这些行时

  //  skin = new Skin(Gdx.files.internal("uiskin.json"));
  //  textButton = new TextButton("test", skin);
  //  textButton.setPosition(Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 4);

然后将应用程序导出到 Android,它在模拟器上运行得很好(所以当我使用带有我创建的按钮的 .pack 文件并将其加载到皮肤中时没有问题)。

我将问题缩小到这一行:skin = new Skin(Gdx.files.internal("uiskin.json"));

我正在使用 uiskin.json 文件以及来自 GitHub 的相关 uiskin.atlasuiskin.png 文件:uiskin files.

对此有什么想法吗?我觉得很奇怪,我似乎无法在 Android 应用程序中使用皮肤。欢迎任何帮助,谢谢。



编辑 我终于设法从 Eclipse 内部获取了我的模拟器 运行,因此我可以提供堆栈跟踪。我 运行 我在上面使用的程序并将 LogCat 报告导出到一个文本文件,我在下面给出了该文件:

09-10 22:42:10.116: I/art(1876): Not late-enabling -Xcheck:jni (already on)
09-10 22:42:10.337: D/(1876): HostConnection::get() New Host Connection established 0xb451a670, tid 1876
09-10 22:42:10.603: I/AndroidInput(1876): sensor listener setup
09-10 22:42:10.664: D/OpenGLRenderer(1876): Render dirty regions requested: true
09-10 22:42:10.689: D/Atlas(1876): Validating map...
09-10 22:42:10.793: I/art(1876): Background sticky concurrent mark sweep GC freed 1995(134KB) AllocSpace objects, 0(0B) LOS objects, 21% free, 489KB/623KB, paused 34.847ms total 239.093ms
09-10 22:42:10.818: D/(1876): HostConnection::get() New Host Connection established 0xa6e67fa0, tid 1897
09-10 22:42:10.879: I/OpenGLRenderer(1876): Initialized EGL, version 1.4
09-10 22:42:10.957: I/art(1876): Background partial concurrent mark sweep GC freed 133(18KB) AllocSpace objects, 0(0B) LOS objects, 52% free, 471KB/983KB, paused 37.420ms total 136.703ms
09-10 22:42:10.958: D/OpenGLRenderer(1876): Enabling debug mode 0
09-10 22:42:10.977: W/EGL_emulation(1876): eglSurfaceAttrib not implemented
09-10 22:42:10.977: W/OpenGLRenderer(1876): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6e8ca80, error=EGL_SUCCESS
09-10 22:42:11.078: D/(1876): HostConnection::get() New Host Connection established 0xa6e678f0, tid 1894
09-10 22:42:11.133: W/GL2JNIView(1876): creating OpenGL ES 2.0 context
09-10 22:42:11.493: I/GL2(1876): all initialized 2
09-10 22:42:11.493: I/AndroidGraphics(1876): OGL renderer: Android Emulator OpenGL ES Translator (AMD Radeon 6600M and 6700M Series)
09-10 22:42:11.499: I/AndroidGraphics(1876): OGL vendor: Google (ATI Technologies Inc.)
09-10 22:42:11.504: I/AndroidGraphics(1876): OGL version: OpenGL ES 2.0 (4.5.13399 Compatibility Profile Context 15.200.1062.1004)
09-10 22:42:11.504: I/AndroidGraphics(1876): OGL extensions: GL_EXT_debug_marker GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint GL_OES_texture_float GL_OES_texture_float_linear GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_packed_depth_stencil GL_OES_vertex_half_float GL_OES_texture_npot GL_OES_rgb8_rgba8
09-10 22:42:11.504: E/EGL_emulation(1876): [getAttribValue] Bad attribute idx
09-10 22:42:11.504: E/EGL_emulation(1876): tid 1894: eglGetConfigAttrib(606): error 0x3004 (EGL_BAD_ATTRIBUTE)
09-10 22:42:11.508: E/EGL_emulation(1876): [getAttribValue] Bad attribute idx
09-10 22:42:11.508: E/EGL_emulation(1876): tid 1894: eglGetConfigAttrib(606): error 0x3004 (EGL_BAD_ATTRIBUTE)
09-10 22:42:11.508: I/AndroidGraphics(1876): framebuffer: (5, 6, 5, 0)
09-10 22:42:11.509: I/AndroidGraphics(1876): depthbuffer: (16)
09-10 22:42:11.509: I/AndroidGraphics(1876): stencilbuffer: (0)
09-10 22:42:11.509: I/AndroidGraphics(1876): samples: (0)
09-10 22:42:11.509: I/AndroidGraphics(1876): coverage sampling: (false)
09-10 22:42:11.527: I/AndroidGraphics(1876): Managed meshes/app: { }
09-10 22:42:11.527: I/AndroidGraphics(1876): Managed textures/app: { }
09-10 22:42:11.527: I/AndroidGraphics(1876): Managed cubemap/app: { }
09-10 22:42:11.528: I/AndroidGraphics(1876): Managed shaders/app: { }
09-10 22:42:11.528: I/AndroidGraphics(1876): Managed buffers/app: { }
09-10 22:42:12.611: I/art(1876): Background partial concurrent mark sweep GC freed 236(29KB) AllocSpace objects, 1(93KB) LOS objects, 35% free, 932KB/1444KB, paused 33.449ms total 54.689ms
09-10 22:42:12.611: I/art(1876): --------- beginning of crash
09-10 22:42:12.621: E/AndroidRuntime(1876): FATAL EXCEPTION: GLThread 117
09-10 22:42:12.621: E/AndroidRuntime(1876): Process: com.mainTest.android, PID: 1876
09-10 22:42:12.621: E/AndroidRuntime(1876): com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:97)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:74)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.mainTest.AndroidTester.create(AndroidTester.java:30)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
09-10 22:42:12.621: E/AndroidRuntime(1876): Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.fromJson(Json.java:683)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:95)
09-10 22:42:12.621: E/AndroidRuntime(1876):     ... 5 more
09-10 22:42:12.621: E/AndroidRuntime(1876): Caused by: com.badlogic.gdx.utils.SerializationException: Font file not found: default.fnt
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.read(Skin.java:446)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.read(Skin.java:437)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.readValue(Json.java:873)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.readValue(Skin.java:404)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.readValue(Json.java:834)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.readNamedObjects(Skin.java:425)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.read(Skin.java:414)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.read(Skin.java:410)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.readValue(Json.java:873)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.scenes.scene2d.ui.Skin.readValue(Skin.java:404)
09-10 22:42:12.621: E/AndroidRuntime(1876):     at com.badlogic.gdx.utils.Json.fromJson(Json.java:681)
09-10 22:42:12.621: E/AndroidRuntime(1876):     ... 6 more
09-10 22:42:13.031: I/AndroidInput(1876): sensor listener tear down
09-10 22:42:13.031: I/AndroidGraphics(1876): Managed meshes/app: { }
09-10 22:42:13.031: I/AndroidGraphics(1876): Managed textures/app: { }
09-10 22:42:13.031: I/AndroidGraphics(1876): Managed cubemap/app: { }
09-10 22:42:13.032: I/AndroidGraphics(1876): Managed shaders/app: { }
09-10 22:42:13.032: I/AndroidGraphics(1876): Managed buffers/app: { }

我解决了这个问题。根据堆栈跟踪,未找到文件 default.fnt,抛出一个 SerializationException.

显然,文件 default.fntdefault.png 也必须位于 Assets 文件夹中才能在 Android 上启动,但从桌面启动时则不需要。 (如果我错了纠正我)。 添加文件后,皮肤加载成功,应用程序不再崩溃。

我将此标记为解决了其他有相同问题的人的问题,以及对文件的 link: default.fnt & default.png.