raeleus/skin-composer

com.badlogic.gdx.utils.SerializationException: Error reading file: Skin

Closed this issue · 2 comments

I created simple skin with TTF font.

After export i got:
Skin:

{
Color: {
	clr_black: {
		hex: 000000ff
	}
}
com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator: {
	fnt_secret: {
		font: secret.ttf
		size: 12
		mono: false
		color: clr_black
		gamma: 1.8
		renderCount: 2
		borderWidth: 0
		borderStraight: false
		borderGamma: 1.8
		shadowOffsetX: 0
		shadowOffsetY: 0
		spaceX: 0
		spaceY: 0
		kerning: true
		flip: false
		genMipMaps: false
		incremental: false
		hinting: AutoMedium
		minFilter: Nearest
		magFilter: Nearest
		characters: " !\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz
	}
}
LabelStyle: {
	lbl_secret: {
		font: fnt_secret
		fontColor: clr_black
		background: pch9_secret
	}
}
}

I used this code to load textures and skin:

@Override
  public void create ()
  {
    _textureAtlas = new TextureAtlas ("TextureAtlas.atlas");
    _skin = new Skin (Gdx.files.internal ("Skin"), _textureAtlas);
}

In result, i have error:
com.badlogic.gdx.utils.SerializationException: Error reading file: Skin.json at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:104) at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:89) at com.secret.Secret.create(Secret.java:73) at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:151) at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:128) Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: Skin.json at com.badlogic.gdx.utils.Json.fromJson(Json.java:758) at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:102) ... 4 more Caused by: com.badlogic.gdx.utils.SerializationException: Class cannot be created (missing no-arg constructor): com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator at com.badlogic.gdx.utils.Json.newInstance(Json.java:1158) at com.badlogic.gdx.utils.Json.readValue(Json.java:970) at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:436) at com.badlogic.gdx.utils.Json.readValue(Json.java:928) at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.readNamedObjects(Skin.java:485) at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:474) at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:468) at com.badlogic.gdx.utils.Json.readValue(Json.java:962) at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:436) at com.badlogic.gdx.utils.Json.fromJson(Json.java:756) ... 5 more Caused by: com.badlogic.gdx.utils.reflect.ReflectionException: Could not instantiate instance of class: com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator at com.badlogic.gdx.utils.reflect.ClassReflection.newInstance(ClassReflection.java:95) at com.badlogic.gdx.utils.Json.newInstance(Json.java:1140) ... 14 more Caused by: java.lang.InstantiationException: com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator at java.lang.Class.newInstance(Class.java:427) at com.badlogic.gdx.utils.reflect.ClassReflection.newInstance(ClassReflection.java:93) ... 15 more Caused by: java.lang.NoSuchMethodException: com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.<init>() at java.lang.Class.getConstructor0(Class.java:3082) at java.lang.Class.newInstance(Class.java:412) ... 16 more

I can see, that Class cannot be created (missing no-arg constructor): com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator, so... how i can use it?

Hello. You must use a custom serializer to use Freetype in skin JSON's. Please see the wiki page: https://github.com/raeleus/skin-composer/wiki/Creating-FreeType-Fonts#using-a-custom-serializer
There is also information in the app when you create the freetype font. Thanks.

@raeleus Thanks