Android 缺少标签样式字体

Android 缺少标签样式字体,android,libgdx,Android,Libgdx,我为我的游戏上了这门课,我希望highscore这个标签是用CourierNew写的。.fnt和.png文件位于assets文件夹中 package com.joelbrun.jetskirider.screens; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20;

我为我的游戏上了这门课,我希望highscore这个标签是用CourierNew写的。.fnt和.png文件位于assets文件夹中

package com.joelbrun.jetskirider.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

public class MainMenu implements Screen {

    private Stage stage;
    private Table table;
    private Label highscore;
    private Button startButton, removeAdsButton;
    private CheckBox muteCheckbox;
    private BitmapFont CourierNew;
    public int score = 0;

    @Override
    public void show() {
        stage = new Stage();
        table = new Table();
        table.setFillParent(true);
        CourierNew = new BitmapFont(Gdx.files.internal("CourierNew.fnt"), false);

        Button.ButtonStyle startButtonStyle = new Button.ButtonStyle();
        startButtonStyle.up = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("startButtonUp.png"))));
        startButtonStyle.down = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("startButtonDown.png"))));

        Button.ButtonStyle removeAdsButtonStyle = new Button.ButtonStyle();
        removeAdsButtonStyle.up = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("removeAdsButtonUp.png"))));
        removeAdsButtonStyle.down = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("removeAdsButtonDown.png"))));

        CheckBox.CheckBoxStyle muteCheckboxStyle = new CheckBox.CheckBoxStyle();
        muteCheckboxStyle.checkboxOn = new TextureRegionDrawable(new TextureRegion(new Texture("muteCheckboxChecked.png")));
        muteCheckboxStyle.checkboxOff = new TextureRegionDrawable(new TextureRegion(new Texture("muteCheckboxUnchecked.png")));

        Label.LabelStyle highscoreStyle = new Label.LabelStyle(CourierNew, Color.YELLOW);

        String formatted = Integer.toString(score);
        startButton = new Button(startButtonStyle);
        removeAdsButton = new Button(removeAdsButtonStyle);
        muteCheckbox = new CheckBox(null, muteCheckboxStyle);
        highscore = new Label(formatted, highscoreStyle);

        table.add(startButton);
        table.debug();
        stage.addActor(table);


    }

    @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 resize(int width, int height) {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {
        stage.dispose();
    }
}
然而,我总是得到错误:

06-27 14:44:55.157  15191-15235/com.joelbrun.jetskirider.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 78201
Process: com.joelbrun.jetskirider.android, PID: 15191
java.lang.IllegalArgumentException: Missing LabelStyle font.
        at com.badlogic.gdx.scenes.scene2d.ui.Label.setStyle(Label.java:77)
        at com.badlogic.gdx.scenes.scene2d.ui.Label.<init>(Label.java:71)
        at com.badlogic.gdx.scenes.scene2d.ui.TextButton.<init>(TextButton.java:46)
        at com.badlogic.gdx.scenes.scene2d.ui.CheckBox.<init>(CheckBox.java:41)
        at com.joelbrun.jetskirider.screens.MainMenu.show(MainMenu.java:51)
        at com.badlogic.gdx.Game.setScreen(Game.java:61)
        at com.joelbrun.jetskirider.screens.Splash$1.onEvent(Splash.java:38)
        at aurelienribon.tweenengine.BaseTween.callCallback(BaseTween.java:380)
        at aurelienribon.tweenengine.BaseTween.updateStep(BaseTween.java:521)
        at aurelienribon.tweenengine.BaseTween.update(BaseTween.java:424)
        at aurelienribon.tweenengine.TweenManager.update(TweenManager.java:166)
        at com.joelbrun.jetskirider.screens.Splash.render(Splash.java:48)
        at com.badlogic.gdx.Game.render(Game.java:46)
        at com.joelbrun.jetskirider.JetskiRider.render(JetskiRider.java:35)
        at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
06-27 14:44:55.157 15191-15235/com.joelbrun.jetskirider.android E/AndroidRuntime﹕ 致命异常:GL78201线程
进程:com.joelbrun.jetskirider.android,PID:15191
java.lang.IllegalArgumentException:缺少LabelStyle字体。
在com.badlogic.gdx.scenes.scene2d.ui.Label.setStyle(Label.java:77)上
位于com.badlogic.gdx.scenes.scene2d.ui.Label.(Label.java:71)
位于com.badlogic.gdx.scenes.scene2d.ui.TextButton.(TextButton.java:46)
位于com.badlogic.gdx.scenes.scene2d.ui.CheckBox.(CheckBox.java:41)
位于com.joelbrun.jetskirider.screens.MainMenu.show(MainMenu.java:51)
在com.badlogic.gdx.Game.setScreen上(Game.java:61)
位于com.joelbrun.jetskirider.screens.Splash$1.onEvent(Splash.java:38)
在aurelianribon.tweenegine.BaseTween.callCallback(BaseTween.java:380)
在aurelianribon.tweenegine.BaseTween.updateStep(BaseTween.java:521)
更新(BaseTween.java:424)
更新(TweenManager.java:166)
位于com.joelbrun.jetskirider.screens.Splash.render(Splash.java:48)
位于com.badlogic.gdx.Game.render(Game.java:46)
位于com.joelbrun.jetskirider.jetskirider.render(jetskirider.java:35)
位于com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
位于android.opengl.GLSurfaceView$GLThread.guarderun(GLSurfaceView.java:1522)
位于android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)

怎么了?我已经试了很多。。。希望任何人都能帮助你,如果你跟踪你发布的回溯,它会引导你找到

com.badlogic.gdx.scenes.scene2d.ui.Label.setStyle(Label.java:77)
如果查看,您将看到(在
setStyle
方法中):

这是你看到的一个例外。因此,问题在于用于初始化
mutexcheckbox
(即
mutexcheckboxstyle
)的
Style
对象将
null
作为其“
字体
”。这个问题很容易解决。调用
mutexcheckbox=new复选框之前(null,mutexcheckboxstyle)初始化
mutexcheckboxstyle
font

muteCheckboxStyle.font = CourierNew;

噢,ofc!我一直认为错误是因为标签
muteCheckboxStyle.font = CourierNew;