1

学习 LibGDX。使用 Android-IDE (AIDE)。遵循本教程关于使用皮肤的信:

https://www.gamefromscratch.com/post/2013/12/18/LibGDX-Tutorial-9-Scene2D-Part-3-UI-Skins.aspx

在 Logcat 中看到此错误:

FATAL EXCEPTION: GLThread 11270
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               Process: com.suchuu.gfstut9pt4, PID: 11269
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               com.badlogic.gdx.utils.SerializationException: Error reading file: data/uiskin.json
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:96)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:73)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.suchuu.gfstut9pt4.MyGdxGame.create(MyGdxGame.java:20)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: data/uiskin.json
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.utils.Json.fromJson(Json.java:662)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:94)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               ... 5 more
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               Caused by: com.badlogic.gdx.utils.SerializationException:
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:430)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:424)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.utils.Json.readValue(Json.java:839)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:418)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.utils.Json.fromJson(Json.java:660)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               ... 6 more
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               Caused by: com.badlogic.gdx.utils.reflect.ReflectionException: Class not found: BitmapFont
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.utils.reflect.ClassReflection.forName(ClassReflection.java:30)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:428)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               ... 10 more
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               Caused by: java.lang.ClassNotFoundException: BitmapFont
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at java.lang.Class.classForName(Native Method)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at java.lang.Class.forName(Class.java:453)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at java.lang.Class.forName(Class.java:378)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at com.badlogic.gdx.utils.reflect.ClassReflection.forName(ClassReflection.java:28)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               ... 11 more
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               Caused by: java.lang.ClassNotFoundException: Didn't find class "BitmapFont" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.suchuu.gfstut9pt4-OcDpQootmuYDXjgvFj_dOA==/base.apk"],nativeLibraryDirectories=[/data/app/com.suchuu.gfstut9pt4-OcDpQootmuYDXjgvFj_dOA==/lib/arm, /system/fake-libs, /data/app/com.suchuu.gfstut9pt4-OcDpQootmuYDXjgvFj_dOA==/base.apk!/lib/armeabi-v7a, /system/lib]]
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
04-25 08:37:00.534 11269 11344 E   AndroidRuntime                               ... 15 more

我编写了与教程中相同的代码,并精确地遵循了每一步。我下载了 UI 资产并将它们放在资产/数据中,所以我不知道我做错了什么。
这是我的代码:

public class MyGdxGame implements ApplicationListener
{
   private SpriteBatch batch;
   private Skin skin;
   private Stage stage;

   @Override
   public void create()
   {
      batch = new SpriteBatch();
      skin = new Skin(Gdx.files.internal("data/uiskin.json"));
      stage = new Stage();

      final TextButton button = new TextButton("Click me!", skin, "default");

      button.setWidth(200f);
      button.setHeight(20f);
    button.setPosition(Gdx.graphics.getWidth() / 2 - 100f, Gdx.graphics.getHeight() / 2 - 10f);

        button.addListener(new ClickListener() {
         @Override
         public void clicked(InputEvent event, float x, float y) {
            button.setText("You clicked the button!");
         }
      });

      stage.addActor(button);

      Gdx.input.setInputProcessor(stage);
   }

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

      stage.draw();
   }

   @Override
   public void dispose()
   {
      batch.dispose();
   }

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

   @Override
   public void pause() {}

   @Override
   public void resume() {}
}
4

0 回答 0