Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用JSON初始化TextButton(Libgdx)时出错_Java_Android_Json_Libgdx_Bitmap Fonts - Fatal编程技术网

Java 使用JSON初始化TextButton(Libgdx)时出错

Java 使用JSON初始化TextButton(Libgdx)时出错,java,android,json,libgdx,bitmap-fonts,Java,Android,Json,Libgdx,Bitmap Fonts,我试图初始化一个TextButton,方法是给它一个包含按钮样式的JSON文件,但是我不断得到以下错误: 线程“LWJGL应用程序”中出现异常 java.lang.IllegalArgumentException:缺少LabelStyle字体 在研究了错误的原因之后,当您忘记将字体作为textbutonstyle的一部分时,似乎会显示此消息,但是我确实将其包含在JSON文件中,因此我不知道为什么它会一直显示 这是我的json文件 { "com.badlogic.gdx.graphics

我试图初始化一个
TextButton
,方法是给它一个包含按钮样式的JSON文件,但是我不断得到以下错误:

线程“LWJGL应用程序”中出现异常 java.lang.IllegalArgumentException:缺少LabelStyle字体

在研究了错误的原因之后,当您忘记将字体作为
textbutonstyle
的一部分时,似乎会显示此消息,但是我确实将其包含在JSON文件中,因此我不知道为什么它会一直显示

这是我的json文件

{

    "com.badlogic.gdx.graphics.Color":{
    "golden":{"r":255,"g":215,"b":0,"a":1}

    },
    "com.badlogic.gdx.graphics.g2d.BitmapFont": {
      "arcade": {"file": "arcade.fnt"}

    },

    "com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle": {
            "default": {
                    "font": arcade,
                    "fontColor": golden
            }
    },

    "com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
            "buttonstyle1": {

                    "up": "unpressedtextbutton",
                    "down": "pressedtextbutton",
                    "font": arcade
    }
    }
}
在代码中,我初始化按钮如下:

Skin skin = new Skin(Gdx.files.internal("buttonstyles.json"),new TextureAtlas(Gdx.files.internal("uistuff.atlas")));
myTextButton = new TextButton("text of the button",skin,"buttonstyle1")
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
  default: { font: default-font, fontColor: white }
}

我的理论是,不知何故,它并没有读取字体文件“arcade.fnt”,我假设它读取文件的目录是assets文件夹,这就是我的“arcade.fnt”文件所在的位置

很抱歉,我好像犯了一个愚蠢的错误。因为我在JSON文件中声明了字体,所以我删除了我以前在代码中用于定义按钮样式的字体,并且后来在标签样式中使用了该字体,因此发现该字体为null,并给出了错误

它是这样工作的吗?这位官员是这样做的:

Skin skin = new Skin(Gdx.files.internal("buttonstyles.json"),new TextureAtlas(Gdx.files.internal("uistuff.atlas")));
myTextButton = new TextButton("text of the button",skin,"buttonstyle1")
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
  default: { font: default-font, fontColor: white }
}
根本不需要引号,甚至字体也不需要引号

com.badlogic.gdx.graphics.g2d.BitmapFont: { 
  default-font: { file: default.fnt } 
},

可能不是合适的JSON,但libgdx有自己的轻量级JSON样式。

尝试将arcade放在引号中,即
“font”:“arcade”
我认为您应该在您的JOSN中使用
{“file”:“assets/arcade.fnt”}
file@OmarAbdelhafiz如果我这样写目录,我会得到“找不到字体文件:assets/arcade.fnt”我认为这只适用于桌面应用程序,指针本身基于assets文件夹。调用/arcade.fnt(可能还需要
/
)就足够了