Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error reading file skin.json libgdx

I am trying to create a main menu for a game that my friends and I are are attempting to make. We work with Eclipse + LibGdx, and I genuinely have no idea what I am doing. I am using code directly from, and I have been unable to find any help on any blog/forum/tutorial. (http://www.gamefromscratch.com/post/2015/02/03/LibGDX-Video-Tutorial-Scene2D-UI-Widgets-Layout-and-Skins.

    package com.mygdx.game;
    import com.badlogic.gdx.ApplicationAdapter;
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.graphics.GL20;
    import com.badlogic.gdx.graphics.Texture;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    import com.badlogic.gdx.scenes.scene2d.InputEvent;
    import com.badlogic.gdx.scenes.scene2d.Stage;
    import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
    import com.badlogic.gdx.scenes.scene2d.ui.Skin;
    import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
    import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
    import com.badlogic.gdx.utils.Timer; 
    import com.badlogic.gdx.utils.viewport.ScreenViewport;

    public class MyGdxGame extends ApplicationAdapter {
    private Skin skin;  
    private Stage stage;

    @Override
    public void create () {

    skin = new Skin(Gdx.files.internal("uiskin.json"));
    stage = new Stage(new ScreenViewport());

    final TextButton button = new TextButton("Click Me",skin,"default");
    button.setWidth(200);
    button.setHeight(50);

    final Dialog dialog = new Dialog("Click Message",skin);

    button.addListener(new ClickListener(){
       @Override
       public void clicked(InputEvent event, float x, float y) {
          dialog.show(stage);
          Timer.schedule(new Timer.Task() {
             @Override
             public void run() {
                dialog.hide();
             }
          }, 10);
       }
    });
    stage.addActor(button);

    Gdx.input.setInputProcessor(stage);
 }

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

 }

     public static void main(String[] args)
     {;}
}

uiskin.json file:

    {
     com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: Razer.fnt     } },
      com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
      default: { down: default-round-down, up: default-round, font: default-font     },
      },

    com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
    default:  {
    titleFont: default-font
         }
       }
    }

desktoplauncher:

    package com.mygdx.game.desktop;

    import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
    import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
    import com.mygdx.game.MyGdxGame;

    public class DesktopLauncher {
        public static void main (String[] arg) {
            LwjglApplicationConfiguration config = new       LwjglApplicationConfiguration();
        new LwjglApplication(new MyGdxGame(), config);
    }
}

errors:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:97)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.(Skin.java:74)
    at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:26)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:694)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:95)
    ... 4 more
Caused by: com.badlogic.gdx.utils.SerializationException: Font file not found: Razer.fnt
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:452)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:443)
    at com.badlogic.gdx.utils.Json.readValue(Json.java:884)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:408)
    at com.badlogic.gdx.utils.Json.readValue(Json.java:852)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.readNamedObjects(Skin.java:429)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:418)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:414)
    at com.badlogic.gdx.utils.Json.readValue(Json.java:884)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:408)
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:692)
    ... 5 more

Thanks. Keep in my mind I am completely lost and am on my last resort. Sorry about any mistakes I made in this post!!

-ed

like image 938
Ed Leko Avatar asked Jul 15 '26 05:07

Ed Leko


1 Answers

That error is basically saying there's something wrong with the skin json.

The format though seems pretty fine, however I think there is more in the stacktrace. Please check out the path to Razer.fnt.

If that doesn't fix it, paste here the full stacktrace.

like image 52
Fechy Avatar answered Jul 17 '26 14:07

Fechy