Search code examples
javajsonlibgdx

JSON Issue: No List$ListStyle registered with name: default


I'm currently creating a game using the Libgdx Java framework, and I am trying to create an Inventory system in which a table is created using a Json file.

The JSON File I am using is called uiskin.json.

When I create an instance of Inventory class (which uses the uiskin.json file) It gives the exception

No com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle registered with name: default

The error in the Inventory class occurs at line 28, where it makes use of the skin file, which uses the json file.

This is the JSON File:

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

This is the class inventory which makes use of the uiskin.json file.

Exception occurs at line 28 of the inventory class.

package com.sps.game.Inventory2;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop;
import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Payload;
import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Source;
import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Target;
import com.sps.game.Utility;

public class Inventory extends ScreenAdapter {

    private Stage stage = new Stage();
    public String UISKIN_PATH = "core/assets/Inventory/uiskin.json";

    public Inventory() {
        final Skin skin = new Skin();
        skin.add("uiskin", UISKIN_PATH);
        stage.setDebugAll(true);

        final List<String> inventory = new List<String>(skin);
        final List<String> sell = new List<String>(skin);

        inventory.setItems("Axe", "Fuel", "Helmet", "Flux Capacitor", "Shoes", "Hamster", "Hammer", "Pirates Eye", "Cucumber");
        Table table = new Table(skin);
        table.setFillParent(true);
        stage.addActor(table);

        table.defaults();
        table.add(inventory);
        table.add("Merchant").row();
        table.add(inventory).expand().fill();
        table.add(sell).expand().fill();

        DragAndDrop dnd = new DragAndDrop();
        dnd.addSource(new Source(inventory) {
            final DragAndDrop.Payload payload = new Payload();

            @Override
            public Payload dragStart(InputEvent event, float x, float y, int pointer) {
                String item = inventory.getSelected(); //get the item from the inventory
                payload.setObject(item);               //set the item to the payload
                inventory.getItems().removeIndex(inventory.getSelectedIndex()); //remove the selected item from the inventory
                payload.setDragActor(new Label(item, skin)); //set the drag actor to be the payload.
                payload.setInvalidDragActor(new Label(item + " (\"No thanks!\")", skin));
                payload.setValidDragActor(new Label(item + " (\"I'll buy this!\")", skin));
                return payload;
            }

            @Override
            public void dragStop(InputEvent event, float x, float y, int pointer, Payload payload, Target target) {
                if (target == null)
                    inventory.getItems().add((String) payload.getObject());
            }
        });

        dnd.addTarget(new Target(sell) {
            @Override
            public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
                return !"Cucumber".equals(payload.getObject());
            }

            @Override
            public void drop(Source source, Payload payload, float x, float y, int pointer) {
                sell.getItems().add((String) payload.getObject());
            }
        });
    }

    @Override
    public void show() {
        Gdx.input.setInputProcessor(stage);
    }

    @Override
    public void resize(int width, int height) {
        stage.getViewport().update(width, height, true);
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.act(delta);
        stage.draw();
    }

    @Override
    public void dispose() {
        stage.dispose();
    }

}

Solution

  • I have fixed it. The IDE was not reading it as a JSON file. I installed the libgdx plugin and it detected the JSON file.