LibGdx [FATAL EXCEPTION]加载皮肤.json文件

时间:2016-02-12 15:28:58

标签: java android json intellij-idea libgdx

我正在使用Intellij。一切都运行良好,APK已部署在我的Android中,但它只是保持黑屏并回到家里说"'游戏'停止:

    1023-1051/? E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 1591
Process: net.mygdx.game.android, PID: 1023
com.badlogic.gdx.utils.ax: Error reading file: jsonSkin.json
        at com.badlogic.gdx.e.a.a.i.a(Unknown Source)
        at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source)
        at net.mygdx.game.a.a(Unknown Source)
        at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
 Caused by: com.badlogic.gdx.utils.ax: Error reading file: skins/jsonSkin.json
        at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source)
            at org.mygdx.gam.a.a(Unknown Source)
            at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
 Caused by: com.badlogic.gdx.utils.ax:
        at com.badlogic.gdx.e.a.a.k.a(Unknown Source)
        at com.badlogic.gdx.e.a.a.k.b(Unknown Source)
        at com.badlogic.gdx.utils.k.a(Unknown Source)
        at com.badlogic.gdx.e.a.a.j.a(Unknown Source)
            at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source)
            at net.mygdx.game.a.a(Unknown Source)
            at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
 Caused by: com.badlogic.gdx.utils.b.e: Class not found: com.badlogic.gdx.graphics.g2d.BitmapFont
        at com.badlogic.gdx.utils.b.b.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.k.b(Unknown Source)
            at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.j.a(Unknown Source)
            at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source)
            at net.mygdx.game.a.a(Unknown Source)
            at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
 Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.graphics.g2d.BitmapFont
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:251)
        at java.lang.Class.forName(Class.java:216)
            at com.badlogic.gdx.utils.b.b.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.k.b(Unknown Source)
            at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.j.a(Unknown Source)
            at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source)
            at net.mygdx.game.a.a(Unknown Source)
            at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
 Caused by: java.lang.NoClassDefFoundError: com/badlogic/gdx/graphics/g2d/BitmapFont
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:251)
            at java.lang.Class.forName(Class.java:216)
            at com.badlogic.gdx.utils.b.b.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.k.b(Unknown Source)
            at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.j.a(Unknown Source)
            at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source)
            at org.mygdx.gam.a.a(Unknown Source)
            at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.badlogic.gdx.graphics.g2d.BitmapFont" on path: DexPathList[[zip file "/data/app/org.mygdx.gam.android-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.mygdx.gam.android-1, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:251)
            at java.lang.Class.forName(Class.java:216)
            at com.badlogic.gdx.utils.b.b.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.k.b(Unknown Source)
            at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.j.a(Unknown Source)
            at com.badlogic.gdx.utils.k.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.a(Unknown Source)
            at com.badlogic.gdx.e.a.a.i.<init>(Unknown Source)
            at org.mygdx.gam.a.a(Unknown Source)
            at com.badlogic.gdx.backends.android.i.onSurfaceChanged(Unknown Source)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)

这是我的.json文件;

{
com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } },
com.badlogic.gdx.graphics.Color: {
    green: { a: 1, b: 0, g: 1, r: 0 },
    white: { a: 1, b: 1, g: 1, r: 1 },
    red: { a: 1, b: 0, g: 0, r: 1 },
    black: { a: 1, b: 0, g: 0, r: 0 },
},
com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: {
    dialogDim: { name: white, color: { r: 0, g: 0, b: 0, a: 0.45 } },
},
com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: {
    default: { down: default-round-down, up: default-round },
    toggle: { down: default-round-down, checked: default-round-down, up: default-round }
},
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
    default: { down: default-round-down, up: default-round, font: default-font, fontColor: white },
    toggle: { down: default-round-down, up: default-round, checked: default-round-down, font: default-font, fontColor: white, downFontColor: red }
},
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
    default: { vScroll: default-scroll, hScrollKnob: default-round-large, background: default-rect, hScroll: default-scroll, vScrollKnob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
    default: {
        font: default-font, fontColor: white, background: default-select,
        scrollStyle: default,
        listStyle: { font: default-font, selection: default-select-selection }
    }
},
com.badlogic.gdx.scenes.scene2d.ui.SplitPane$SplitPaneStyle: {
    default-vertical: { handle: default-splitpane-vertical },
    default-horizontal: { handle: default-splitpane }
},
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
    default: { titleFont: default-font, background: default-window, titleFontColor: white },
    dialog: { titleFont: default-font, background: default-window, titleFontColor: white, stageBackground: dialogDim }
},
com.badlogic.gdx.scenes.scene2d.ui.ProgressBar$ProgressBarStyle: {
    default-horizontal: { background: default-slider, knob: default-slider-knob },
    default-vertical: { background: default-slider, knob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: {
    default-horizontal: { background: default-slider, knob: default-slider-knob },
    default-vertical: { background: default-slider, knob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
    default: { font: default-font, fontColor: white }
},
com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: {
    default: { selection: selection, background: textfield, font: default-font, fontColor: white, cursor: cursor }
},
com.badlogic.gdx.scenes.scene2d.ui.CheckBox$CheckBoxStyle: {
    default: { checkboxOn: check-on, checkboxOff: check-off, font: default-font, fontColor: white }
},
com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: {
    default: { fontColorUnselected: white, selection: selection, fontColorSelected: white, font: default-font }
},
com.badlogic.gdx.scenes.scene2d.ui.Touchpad$TouchpadStyle: {
    default: { background: default-pane, knob: default-round-large }
},
com.badlogic.gdx.scenes.scene2d.ui.Tree$TreeStyle: {
    default: { minus: tree-minus, plus: tree-plus, selection: default-select-selection }
},
com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle: {
    default: {
        label: { font: default-font, fontColor: white },
        background: default-pane, wrapWidth: 150
    }
},
}

这些线条很奇怪,因为如果我摆脱它们,程序就可以正常工作,除了显然没有出现的按钮;

skin = new Skin(Gdx.files.internal("jsonSkin.json"));
TextButton btnStart = new TextButton("Start!!", skin);
btnStart.setPosition(50f,400f);
btnStart.setSize(260f,60f);
mainMenu.addActor(btnStart);

3 个答案:

答案 0 :(得分:4)

把它放在你的配置中:

 -keep class com.badlogic.**{
   **[] $VALUES;
    *;
}

它可以解决这个问题,并解决问题。

编辑:

以上是禁用特定包的所有ProGuard’s优点的顶级规则。没有萎缩,没有混淆;不是为了课程,不是为了会员。

Proguard对我们在皮肤文件中使用的类进行模糊处理,Skin通过反射加载类,因此我们必须不允许 Proguard更改这些类的名称。

  1. 包中的双星号表示该顶级包下每个包下的每个类;
  2. 花括号内的星号适用于这些类中的每个成员(变量,方法和常量)。

答案 1 :(得分:1)

问题是json序列化器需要确切的字段名称来完成它的工作。

Abhishek是正确的,但我只需要忽略仅对scene2d包收缩,所以我把它放在 proguard-rules.pro 文件

 -keep class com.badlogic.gdx.scenes.scene2d.ui.**{
    **[] $VALUES;
     *;
 }

它将优化除皮肤加载器及其组件之外的所有其他代码。

如果你正在使用自己的类进行json de / serializing,你还需要输入类似的内容。

 -keep class com.your.game.data.**{
    **[] $VALUES;
     *;
 }

以下是在Android Studio上为初学者找到 proguard-rules.pro 文件的屏幕截图 enter image description here

答案 2 :(得分:0)

将其放入 proguard规则

-keep class com.badlogic.gdx.graphics.g2d.BitmapFont