1

I am trying to make a Table that has a Skin based on libgdx's default LabelStyle and BitmapFont through the use of a json file. (this file is supposed to hold the references of these two objects) In doing this I am getting some unclear errors. For instance:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: ui/uiskin.json
        at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:96)
        at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:73)
        at com.naitsirc.Interpolation.Test.show(Test.java:47)
        at com.badlogic.gdx.Game.setScreen(Game.java:61)
        at com.naitsirc.Interpolation.InterpolationTest.create(InterpolationTest.java:9)
        at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
        at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
    Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: ui/uiskin.json
        at com.badlogic.gdx.utils.Json.fromJson(Json.java:662)
        at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:94)
        ... 6 more
    Caused by: com.badlogic.gdx.utils.SerializationException: Serialization trace:
    font (com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle)
        at com.badlogic.gdx.utils.Json.readFields(Json.java:762)
        at com.badlogic.gdx.utils.Json.readValue(Json.java:865)
        at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:418)
        at com.badlogic.gdx.utils.Json.readValue(Json.java:809)
        at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.readNamedObjects(Skin.java:439)
        at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:428)
        at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:424)
        at com.badlogic.gdx.utils.Json.readValue(Json.java:839)
        at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:418)
        at com.badlogic.gdx.utils.Json.fromJson(Json.java:660)
        ... 7 more
    Caused by: com.badlogic.gdx.utils.GdxRuntimeException: No com.badlogic.gdx.graphics.g2d.BitmapFont registered with name: default-font
        at com.badlogic.gdx.scenes.scene2d.ui.Skin.get(Skin.java:145)
        at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:417)
        at com.badlogic.gdx.utils.Json.readFields(Json.java:755)
        ... 16 more*

This is where I create my skin with the json:

public void show() {
    Gdx.input.setInputProcessor(stage = new Stage());

    skin = new Skin(Gdx.files.internal("ui/uiskin.json")); // HERE

    container = new Table();
    table = new Table(skin);

    for(int i = 0; i < interpolationNames.length; i++){
        //table.row();
        table.add(interpolationNames[i]); // I am trying to populate these table cells
    }

    ScrollPane pane = new ScrollPane(table);
    container.add(pane);        

    stage.addActor(container);

    renderer = new ShapeRenderer();
}

My json file:

{
    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 }
    }
}

What am I doing incorrectly?


Note

I seem to have the same problem as here but what I did is the same thing, and its not working.

Community
  • 1
  • 1
Cristian Gutu
  • 1,221
  • 1
  • 11
  • 24

1 Answers1

0

The problem is with the order of the objects in my json file and also I missed some required objects for the ScrollPane and Color. In addition I needed to add default.fnt and default.png to my assets folder from here. Basically its supposed to look like this:

{
    com.badlogic.gdx.graphics.g2d.BitmapFont: { 
        default-font: { file: default.fnt } 
    },
    com.badlogic.gdx.graphics.Color: {
        white: { a: 1, b: 1, g: 1, r: 1 },
    },
    com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
        default: { font: default-font, fontColor: white }
    },
    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 }
    }
}

This said I still don't understand why a certain order is required nor do I know how to find out which specific objects need to be placed in the json file. The only way I figured out that I need these specifically is by the errors Eclipse gave me.

Cristian Gutu
  • 1,221
  • 1
  • 11
  • 24