2012-11-20 3 views
2

json 파일에 정의 된 스킨이있는 Textbutton을 만들려고합니다. 저는 libgdx 초보자입니다. 모니터와 키보드 사이에 문제가있을 수 있습니다.) 도와 주시면 감사하겠습니다.java.lang.ClassNotFoundException : resources?

LibGDX 버전 을 : 신선한 힘내 - 풀 (20 2012 11월) ("데이터/button.json"에서)

내 JSON은 :

{ 
     resources: { 
       com.badlogic.gdx.graphics.Color: { 
         white: { r: 1, g: 1, b: 1, a: 1 }, 
         downFontColor: { r: 1, g: 0.1, b: 0.2, a: 1 } 
       }, 
       com.badlogic.gdx.graphics.g2d.BitmapFont: { 
         default-font: { file: default.fnt } 
       } 
     }, 
     styles: { 
       com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: { 
         default: { 
           font: default-font, 
           downFontColor: downFontColor, 
           fontColor: white 
         } 
       } 
     } 
} 

이 실패 할 경우 :

Skin skin = new Skin(Gdx.files.internal("data/button.json")); 

예외 :

JSON 파일없이
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.SerializationException: Error reading file: data/button.json 
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:111) 
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: data/button.json 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:95) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:72) 
    at eu.loecken.tools.virtuallampsi.screens.MenuScreen.createButton(MenuScreen.java:105) 
    at eu.loecken.tools.virtuallampsi.screens.MenuScreen.create(MenuScreen.java:47) 
    at eu.loecken.tools.virtuallampsi.screens.MenuScreen.show(MenuScreen.java:131) 
    at com.badlogic.gdx.Game.setScreen(Game.java:62) 
    at eu.loecken.tools.virtuallampsi.MainGame.create(MainGame.java:48) 
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:125) 
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:108) 
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: data/button.json 
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:596) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:93) 
    ... 8 more 
Caused by: com.badlogic.gdx.utils.SerializationException: 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:424) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:1) 
    at com.badlogic.gdx.utils.Json.readValue(Json.java:762) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:409) 
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:594) 
    ... 9 more 
Caused by: java.lang.ClassNotFoundException: resources 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:422) 
    ... 13 more 

* 근무 코드 : *가 (뭔가가 작동하는 것을 보여주기 위해)

Texture texture = new Texture(Gdx.files.internal(imageURL)); 
textures.add(texture); 

TextureRegion image = new TextureRegion(texture); 
TextureRegion flippedImage = new TextureRegion(image); 
flippedImage.flip(true, true); 
ButtonStyle style = new ButtonStyle(); 
style.up = new TextureRegionDrawable(image); 
style.down = new TextureRegionDrawable(flippedImage); 
return new Button(style); 

업데이트 : 또한이 하나가 작동 :

private final BitmapFont defaultFont = new BitmapFont(
     Gdx.files.internal("data/default.fnt"), false); 
private final Texture btnTexture = new Texture(
     Gdx.files.internal("buttons/lvl.png")); 

private Button createButton(String text) { 
    // Initialize skin 
    // Skin skin = new Skin(Gdx.files.internal("data/button.json")); 
    TextureRegion image = new TextureRegion(btnTexture); 
    TextureRegion flippedImage = new TextureRegion(image); 
    flippedImage.flip(true, true); 
    TextButtonStyle style = new TextButtonStyle(); 
    style.up = new TextureRegionDrawable(image); 
    style.down = new TextureRegionDrawable(flippedImage); 
    style.font = defaultFont; 
    return new TextButton(text, style); 
} 
+0

전체 파일 경로는 무엇입니까? 안드로이드 자산 폴더 안에 있습니까? – idanakav

+0

예, 예. 나는 그 질문을 편집 할 것이다 ... –

답변

4

Skin docs

에 따르면 json 파일의 모양은 다음과 같습니다.
{ 
    className: { 
      name: resource, 
      ... 
    }, 
    className: { 
      name: resource, 
      ... 
    }, 
    ... 
} 

은 "자원"클래스를 검색하기 때문에 당신이 예외가 볼 수 ... 그래서 그냥 예를 들어 위의 템플릿으로 변경 :

{ 
    com.badlogic.gdx.graphics.Color: { 
      white: { r: 1, g: 1, b: 1, a: 1 }, 
      red: { r: 1, g: 0, b: 0, a: 1 }, 
      yellow: { r: 0.5, g: 0.5, b: 0, a: 1 }, 
    }, 
    com.badlogic.gdx.graphics.g2d.BitmapFont: { 
      medium: { file: default.fnt } 
    }, 
    com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: { 
      default: { 
        down: button, up: button, 
        font: medium, fontColor: white 
      }, 
      green: { 
        down: button, up: button, 
        font: medium, fontColor: { r: 0, g: 1, b: 0, a: 1 } 
      } 
    } 

}

PS 버튼입니다 실제 이미지 리소스 또한 skin json 파일의 템플릿이 libgdx의 이전 버전을위한 것이라고 확신합니다.

+0

그것이 그 것이다. 고마워. 맞아, 내가 오래된 템플릿을 사용한 것처럼 보입니다. –

관련 문제