0
\$\begingroup\$

I get an error every time I try to parse this .json file.

Here is the error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: skin/glassy-ui.json
  at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:104)
  at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:81)
  at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:45)
  at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149)
  at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: skin/glassy-ui.json
  at com.badlogic.gdx.utils.Json.fromJson(Json.java:715)
  at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:102)
  ... 4 more
Caused by: com.badlogic.gdx.utils.SerializationException: Error parsing file: skin/glassy-ui.json
  at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:78)
  at com.badlogic.gdx.utils.Json.fromJson(Json.java:713)
  ... 5 more
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: skin\glassy-ui.json (Classpath)
  at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:142)
  at com.badlogic.gdx.files.FileHandle.reader(FileHandle.java:169)
  at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:76)
  ... 6 more

Here is the code:

mySkin = new Skin(Gdx.files.classpath(constants.skin));

I have my references correct and the assets are properly placed in the folder. I'm not sure why it is saying file not found: skin/glassy-ui.json

json code:

{
com.badlogic.gdx.graphics.g2d.BitmapFont: {
  font: {
    file: font-export.fnt
  }
  font-big: {
    file: font-big-export.fnt
  }
}
com.badlogic.gdx.graphics.Color: {
  black: {
    r: 0
    g: 0
    b: 0
    a: 1
  }
  cyan: {
    r: 0
    g: 1
    b: 0.99166656
    a: 1
  }
  dark-cyan: {
    r: 0
    g: 0.39373153
    b: 0.4333333
    a: 1
  }
  white: {
    r: 1
    g: 1
    b: 1
    a: 1
  }
}
com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: {
  pale-blue: {
    name: white
    color: {
      r: 0.48342222
      g: 0.76367503
      b: 0.99333334
      a: 1
    }
  }
  black: {
    name: white
    color: {
      r: 0
      g: 0
      b: 0
      a: 1
    }
  }
}
com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: {
  default: {
    up: button
    down: button-down
  }
  small: {
    up: button-small
    down: button-small-down
  }
}
com.badlogic.gdx.scenes.scene2d.ui.CheckBox$CheckBoxStyle: {
  default: {
    checkboxOn: checkbox
    checkboxOff: checkbox-off
    font: font
    fontColor: white
  }
  radio: {
    checkboxOn: radio-button
    checkboxOff: radio-button-off
    font: font
    fontColor: white
  }
}
com.badlogic.gdx.scenes.scene2d.ui.ImageButton$ImageButtonStyle: {
  default: {
    up: button
    down: button-down
  }
}
com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton$ImageTextButtonStyle: {
  default: {
    font: font-big
    up: button
    down: button-down
  }
}
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
  default: {
    font: font
  }
  big: {
    font: font-big
  }
  black: {
    font: font
    fontColor: black
  }
}
com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: {
  default: {
    font: font
    fontColorSelected: white
    fontColorUnselected: dark-cyan
    selection: pale-blue
    background: list
  }
  plain: {
    font: font
    fontColorSelected: white
    fontColorUnselected: dark-cyan
    selection: pale-blue
  }
}
com.badlogic.gdx.scenes.scene2d.ui.ProgressBar$ProgressBarStyle: {
  default-horizontal: {
    background: progress-bar
    knobBefore: progress-bar-knob
  }
  default-vertical: {
    background: progress-bar-vertical
    knobBefore: progress-bar-knob-vertical
  }
}
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle: {
  default: {
    hScroll: horizontal-scroll-bar
    hScrollKnob: horizontal-scroll-knob
    vScroll: vertical-scroll-bar
    vScrollKnob: vertical-scroll-knob
  }
  scroll: {
    background: list
    hScroll: horizontal-scroll-bar
    hScrollKnob: horizontal-scroll-knob
    vScroll: vertical-scroll-bar
    vScrollKnob: vertical-scroll-knob
  }
}
com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
  default: {
    font: font
    fontColor: dark-cyan
    background: select-box
    scrollStyle: scroll
    listStyle: plain
  }
}
com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: {
  default-horizontal: {
    background: slider
    knob: slider-knob
  }
  default-vertical: {
    background: slider-vertical
    knob: slider-knob
  }
}
com.badlogic.gdx.scenes.scene2d.ui.SplitPane$SplitPaneStyle: {
  default-horizontal: {
    handle: horizontal-split-pane
  }
  default-vertical: {
    handle: vertical-split-pane
  }
}
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
  default: {
    font: font-big
    up: button
    down: button-down
  }
  small: {
    font: font
    up: button-small
    down: button-small-down
  }
}
com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle: {
  default: {
    font: font
    fontColor: black
    background: textfield
    cursor: black
    selection: pale-blue
  }
}
com.badlogic.gdx.scenes.scene2d.ui.Tree$TreeStyle: {
  default: {
    plus: plus
    minus: minus
    selection: pale-blue
  }
}
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
  default: {
    background: window
    titleFont: font
    titleFontColor: black
  }
}
}
\$\endgroup\$
2
\$\begingroup\$

com.badlogic.gdx.utils.GdxRuntimeException: File not found: skin\glassy-ui.json (Classpath)

The json reader can't find your file, you can't fix that by changing the files content.

The first problem is that you're using the classpath file locator, it's described as "should be avoided" in the wiki:

They have their purpose, but should be avoided if possible.

Try

Gdx.files.internal("skin/glassy-ui.json")

Where the file is placed in the "YourProjectName/android/assets/skin" folder (the standard assets-folder).

This is the preferred method to refer to assets in LibGDX:

Internal files are relative to the application’s root or working directory on desktops, relative to the assets directory on Android, and relative to the core/assets/ directory of your GWT project. These files are read-only. If a file can't be found on the internal storage, the file module falls back to searching the file on the classpath. This is necessary if one uses the asset folder linking mechanism of Eclipse, see Project Setup

This only works if you have set up the project correctly (with the setup GUI / gradle) though.

Check the LibGDX Wiki on file handling: LibGDX Wiki - File (Storage) Types

And on Project setup: LibGDX Wiki - Project Setup

\$\endgroup\$
1
\$\begingroup\$

It is not correct JSON, strings in JSON must be surrounded with quotes, and values in object must be comma-separated

For example

{
    "key": "value",
    "number": 1,
    "nested-object": {
        "name": null,
        "array": [{
            "id": 1234
        },{
            "id": 5678
        }]
    }
} 

You always can validate your JSON online

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.