Kapparino
Kapparino

Reputation: 988

Error loading json ui-skin file from android/assets

I have default.json file for setting skin to ui component. The file location previously was in project package core/src/com/mygame, which has the following data:

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

Then I would load that file in onCreate method skin = new Skin(Gdx.files.internal("default.json")); Which is working.

However, now I decided to move that file to android project in assets folder called ui-skins/. Problem is, I'm getting an error when I try to load that file from path Gdx.files.internal("ui-skins/default.json"):

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: ui-skins/default.json
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:98)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:75)
    at com.unknown.game.MyUnknownGame.create(MyUnknownGame.java:32)
    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: ui-skins/default.json
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:694)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:96)
    ... 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:472)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:463)
    at com.badlogic.gdx.utils.Json.readValue(Json.java:884)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:428)
    at com.badlogic.gdx.utils.Json.readValue(Json.java:852)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.readNamedObjects(Skin.java:449)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:438)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:434)
    at com.badlogic.gdx.utils.Json.readValue(Json.java:884)
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:428)
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:692)
    ... 5 more

Upvotes: 0

Views: 409

Answers (2)

Keey
Keey

Reputation: 319

I found your error:

Font file not found: Razer.fnt as stated in the error log.

Remember, that you need your font.fnt file AND your font.png file in the same folderstructure, as it was before(I guess in the same folder, as your JSON file).

Hope that helps

€dit: Further explanation as why you need the font.png
If you look into your .fnt file you'll see, it's only text, which describes the .png of your font. in this .png are the glyphs.

Upvotes: 2

ivofernandes
ivofernandes

Reputation: 39

test your json here

http://jsonlint.com/

you need to put your strings inside quotes, like this:

{ "com.badlogic.gdx.graphics.g2d.BitmapFont": { ...

Upvotes: -1

Related Questions