{"id":6930,"date":"2014-05-11T17:47:10","date_gmt":"2014-05-11T17:47:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/11\/java-lang-classnotfoundexception-resources-collection-of-common-programming-errors\/"},"modified":"2014-05-11T17:47:10","modified_gmt":"2014-05-11T17:47:10","slug":"java-lang-classnotfoundexception-resources-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/11\/java-lang-classnotfoundexception-resources-collection-of-common-programming-errors\/","title":{"rendered":"java.lang.ClassNotFoundException: resources?-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/024d568ee3c7b98593eb864fbae4a93a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAndreas L.<\/p>\n<p>I am trying to create a Textbutton with a skin that is defined in a json file. I am a beginner at libgdx, so maybe the problem is between monitor and keyboard \ud83d\ude09 I hope you can help me.<\/p>\n<p>LibGDX-version: Fresh Git-Pull (20th Nov. 2012)<\/p>\n<p><strong>My json (at &#8220;data\/button.json&#8221;):<\/strong><\/p>\n<pre><code>{\n        resources: {\n                com.badlogic.gdx.graphics.Color: {\n                        white: { r: 1, g: 1, b: 1, a: 1 },\n                        downFontColor: { r: 1, g: 0.1, b: 0.2, a: 1 }\n                },\n                com.badlogic.gdx.graphics.g2d.BitmapFont: {\n                        default-font: { file: default.fnt }\n                }\n        },\n        styles: {\n                com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {\n                        default: {\n                                font: default-font, \n                                downFontColor: downFontColor,\n                                fontColor: white\n                        }\n                }\n        }\n }  \n<\/code><\/pre>\n<p><strong>Where it fails:<\/strong><\/p>\n<pre><code>    Skin skin = new Skin(Gdx.files.internal(\"data\/button.json\"));\n<\/code><\/pre>\n<p><strong>Exception:<\/strong><\/p>\n<pre><code>Exception in thread \"LWJGL Application\" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.SerializationException: Error reading file: data\/button.json\n    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:111)\nCaused by: com.badlogic.gdx.utils.SerializationException: Error reading file: data\/button.json\n    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:95)\n    at com.badlogic.gdx.scenes.scene2d.ui.Skin.(Skin.java:72)\n    at eu.loecken.tools.virtuallampsi.screens.MenuScreen.createButton(MenuScreen.java:105)\n    at eu.loecken.tools.virtuallampsi.screens.MenuScreen.create(MenuScreen.java:47)\n    at eu.loecken.tools.virtuallampsi.screens.MenuScreen.show(MenuScreen.java:131)\n    at com.badlogic.gdx.Game.setScreen(Game.java:62)\n    at eu.loecken.tools.virtuallampsi.MainGame.create(MainGame.java:48)\n    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:125)\n    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:108)\nCaused by: com.badlogic.gdx.utils.SerializationException: Error reading file: data\/button.json\n    at com.badlogic.gdx.utils.Json.fromJson(Json.java:596)\n    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:93)\n    ... 8 more\nCaused by: com.badlogic.gdx.utils.SerializationException: \n    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:424)\n    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:1)\n    at com.badlogic.gdx.utils.Json.readValue(Json.java:762)\n    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:409)\n    at com.badlogic.gdx.utils.Json.fromJson(Json.java:594)\n    ... 9 more\nCaused by: java.lang.ClassNotFoundException: resources\n    at java.net.URLClassLoader$1.run(Unknown Source)\n    at java.security.AccessController.doPrivileged(Native Method)\n    at java.net.URLClassLoader.findClass(Unknown Source)\n    at java.lang.ClassLoader.loadClass(Unknown Source)\n    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)\n    at java.lang.ClassLoader.loadClass(Unknown Source)\n    at java.lang.Class.forName0(Native Method)\n    at java.lang.Class.forName(Unknown Source)\n    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:422)\n    ... 13 more\n<\/code><\/pre>\n<p>*<em>Working code without json-file: *<\/em> (just to show that something works)<\/p>\n<pre><code>Texture texture = new Texture(Gdx.files.internal(imageURL));\ntextures.add(texture);\n\nTextureRegion image = new TextureRegion(texture);\nTextureRegion flippedImage = new TextureRegion(image);\nflippedImage.flip(true, true);\nButtonStyle style = new ButtonStyle();\nstyle.up = new TextureRegionDrawable(image);\nstyle.down = new TextureRegionDrawable(flippedImage);\nreturn new Button(style);\n<\/code><\/pre>\n<p><strong>Update: Also this one is working:<\/strong><\/p>\n<pre><code>private final BitmapFont defaultFont = new BitmapFont(\n        Gdx.files.internal(\"data\/default.fnt\"), false);\nprivate final Texture btnTexture = new Texture(\n        Gdx.files.internal(\"buttons\/lvl.png\"));\n\nprivate Button createButton(String text) {\n    \/\/ Initialize skin\n    \/\/ Skin skin = new Skin(Gdx.files.internal(\"data\/button.json\"));\n    TextureRegion image = new TextureRegion(btnTexture);\n    TextureRegion flippedImage = new TextureRegion(image);\n    flippedImage.flip(true, true);\n    TextButtonStyle style = new TextButtonStyle();\n    style.up = new TextureRegionDrawable(image);\n    style.down = new TextureRegionDrawable(flippedImage);\n    style.font = defaultFont;\n    return new TextButton(text, style);\n}\n<\/code><\/pre>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c6d00a504d0cb98e32a5634edb64ec82?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nidaNakav<\/p>\n<p>this is how your json file should be like , according to Skin docs<\/p>\n<pre><code>{\n    className: {\n            name: resource,\n            ...\n    },\n    className: {\n            name: resource,\n            ...\n    },\n    ...\n}\n<\/code><\/pre>\n<p>as you can see you get the exception since it looks for &#8220;resources&#8221; class .. so just change it to the template above for example:<\/p>\n<pre><code>{\n    com.badlogic.gdx.graphics.Color: {\n            white: { r: 1, g: 1, b: 1, a: 1 },\n            red: { r: 1, g: 0, b: 0, a: 1 },\n            yellow: { r: 0.5, g: 0.5, b: 0, a: 1 },\n    },\n    com.badlogic.gdx.graphics.g2d.BitmapFont: {\n            medium: { file: default.fnt }\n    },\n    com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {\n            default: {\n                    down: button, up: button,\n                    font: medium, fontColor: white\n            },\n            green: {\n                    down: button, up: button,\n                    font: medium, fontColor: { r: 0, g: 1, b: 0, a: 1 }\n            }\n    }\n<\/code><\/pre>\n<p>}<\/p>\n<p>P.S button is an real image resource also i&#8217;m pretty sure your template of the skin json file is for old versions of libgdx<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Andreas L. I am trying to create a Textbutton with a skin that is defined in a json file. I am a beginner at libgdx, so maybe the problem is between monitor and keyboard \ud83d\ude09 I hope you can help me. LibGDX-version: Fresh Git-Pull (20th Nov. 2012) My json (at &#8220;data\/button.json&#8221;): { resources: { com.badlogic.gdx.graphics.Color: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6930","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6930"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6930\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}