While learning a bit of libGDX by creating my mini project i decided that i need text input, created text field, a skin for it, but errors occurs with importing default skin.
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException:
com.badlogic.gdx.utils.SerializationException: Error reading file: data/uiskin.json
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113)
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: data/uiskin.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 com.me.bpmtest.BpmTest.create(BpmTest.java:47)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:127)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: data/uiskin.json
at com.badlogic.gdx.utils.Json.fromJson(Json.java:613)
at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:93)
... 4 more
Caused by: com.badlogic.gdx.utils.SerializationException: Field not found: scrollStyle (com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle)
at com.badlogic.gdx.utils.Json.readFields(Json.java:703)
at com.badlogic.gdx.utils.Json.readValue(Json.java:816)
at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:409)
at com.badlogic.gdx.utils.Json.readValue(Json.java:766)
at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.readNamedObjects(Skin.java:434)
at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:422)
at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:415)
at com.badlogic.gdx.utils.Json.readValue(Json.java:791)
at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:409)
at com.badlogic.gdx.utils.Json.fromJson(Json.java:611)
... 5 more
I use default skin files from here
Here's code snippet of my create function:
public void create() {
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
//Gdx.input.setOnscreenKeyboardVisible(true); - for android later.
AndroidInput listener = new AndroidInput();
stage = new Stage();
textfield = new TextField("", skin);
textfield.setMessageText("Enter Push number");
....
}
I'm really just a beginner here, maybe there is simpler way to get text input? I need to get integer from a user.
Check the tools box on the libgdx launch screen. Then you will have all the default files that are used in many libgdx examples including uiskin.json. After you do that you can just call Gdx.files.internal("uiskin.json")
Related
my problem is, like described in the Title, that i can not integrate an own BitmapFont into my libGDX skin. I searched a lot and there are many Topics with exact my problem, but their solution never work for me. Here is my code:
skin = new Skin();
skin.add("default-font", StaticValues.generateFont(40, Color.BLACK), BitmapFont.class);
FileHandle fileHandle = Gdx.files.internal("scene2d.ui/uiskin.json");
FileHandle atlasFile = fileHandle.sibling("scene2d.ui/uiskin.atlas");
if (atlasFile.exists()) {
skin.addRegions(new TextureAtlas(atlasFile));
}
skin.load(fileHandle);
and now they say that i should remove this line:
com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } },
out of my JSON-File. But then this error occurs:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: scene2d.ui/uiskin.json
at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:98)
...
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: white
is there a simple solution for my problem?
Thanks in advance
Edit:
i already tried one other thing:
Other Solution, not working for me
So I upgraded to the latest nightly and updated my project to remove all calls to GL10 but I am getting this error even though I have removed the reference to it.
Exception in thread "main" java.lang.NoSuchFieldError: useGL20
at com.me.mygdxgame.Main.main(Main.java:10)
This is what the code in the file looks like
package com.me.mygdxgame;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "my-gdx-game";
// cfg.useGL20 = false;
cfg.width = 480;
cfg.height = 320;
new LwjglApplication(new MyGdxGame(), cfg);
}
}
Does anyone have an idea of why I still keep getting this error?
The latest libgdx build has gotten rid of the opengl 1.0 backend so the field cfg.useGL20 is no longer needed. If interested read up here
According to that page
LwjglApplicationConfiguration and AndroidApplicationConfiguration do not have the useGL20 flags anymore.
So eliminate that line and things should be good if you updated each project to the newest nightely. If you are still having problems update projects again to the newest nightly as this is very new to libgdx so there are probably a lot of bugs
I'm trying to figure out how to remove the message error and what cause it.
I created a code for loading external vdo to play on Flash. Coding it inside the Action Script panel is fine so I try to make it as a class. I moved all the code and put it in a class and it works fine too. But, the error message appeared ! even though the file could play correctly.
The error says:
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onMetaData. error=ReferenceError: Error #1069: Property onMetaData not found on vdoloader and there is no default value.
at vdoloader()
This is my code
package {
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
public class vdoloader extends Sprite {
var video;
var nc;
var ns;
public function vdoloader() {
// constructor code
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client=this;
video = new Video(550,400);
addChild (video);
video.attachNetStream(ns);
ns.play("westler.flv");
}
}
}
And then I tried to put something in that vdoloader(), it said something like: "expected 1, got 0."
It is exactly that - you are not handling the meta data event by implementing a function onMetaData. The client of your player is "this", so you should have a public function onMetaData in your class.
An please oh please, use an uppercase first letter for your class name...
EDIT:
In your code you are assigning this as the netstream's client (source: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html):
Associate a client property with an event handler to receive the data
object. Use the NetStream.client property to assign an object to call
specific data handling functions. The object assigned to the
NetStream.client property can listen for the following data points:
onCuePoint(), onImageData(), onMetaData(), onPlayStatus(),
onSeekPoint(), onTextData(), and onXMPData(). Write procedures within
those functions to handle the data object returned from the stream
during playback. See the NetStream.client property for more
information.
So now you just need to create a function onMetaData(md:Object) that should handle the event within the very same class, i.e. vdoloader (<=as you are passing this as the client). You can check the docs how to do it: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#event:onMetaData. I think that Lee Brimelow had a tutorial about this on his site - http://www.gotoandlearn.com. (I am not sure about this but I guess it is worth a try if you are interested)
I'm using this to show the callstack:
throw new Error("show me");
But I'd like to print a longer (deeper) stack because the current one do not show me what I need.
If you don't see more with Error.getStackTrace(), it's probably because there is nothing more in the stack. Except for private internal player calls like [Render] etc.
Look at the deepest item in the call stack, it's probably an event handler of some sort. If so, you can't dig deeper than that.
You can get the stack trace as a string and log it to a file or show it in a text field.
var e:Error = new Error();
var trace:String = e.getStackTrace();
someTextField.text = trace;
Edit:
Using Flash Develop I threw an error and was able to see more than 17 steps of the stack trace :
Error
at Main/func14()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:100]
at Main/func13()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:93]
at Main/func12()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:88]
at Main/func11()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:83]
at Main/func10()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:78]
at Main/func9()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:73]
at Main/func8()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:68]
at Main/func7()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:63]
at Main/func6()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:58]
at Main/func5()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:53]
at Main/func4()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:49]
at Main/func3()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:44]
at Main/func2()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:39]
at Main/func1()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:34]
at Main/onCreationComplete()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:29]
at Main/___Main_Application1_creationComplete()[C:\Users\SGU\Desktop\barisu\misc\flex4test\src\Main.mxml:5]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152]
at mx.core::UIComponent/set initialized()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:1818]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:842]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]
I developed some JUnit tests that extend org.apache.struts2.StrutsTestCase. I used the tutorial on struts.apache.org as my starting point.
Everything was working fine until I modified my simple web application to use Tiles. I have Tiles working fine in the app but now my Action test cases have stopped working.
I'm getting NullPointerException at org.apache.struts2.views.tiles.TilesResult.doExecute when I run the following line of code:
ActionProxy proxy = getActionProxy("/displaytag.action");
The log shows the Struts 2 Action is executing succesfully until it tries to hand it off to TilesResult.doExecute.
I suspect it is because the tests run outside of the container and the tiles.xml is only referenced in the web.xml and therefore my StrutsTestCase tests don't know where to find the definitions in tiles.xml.
Is this making sense?
I'm using Struts 2.2.1.1 and the tiles related jars (v. 2.0.6) included in the Struts distribution.
I'll include a code snippet from my StrutsTestCase but please note everything runs successfully when I run the app from the browser in Tomcat, it only fails when I run the StrutsTestCase outside of Tomcat. And the test cases ran successfully before I added Tiles.
public class TagActionTest extends StrutsTestCase {
static Logger logger = Logger.getLogger(TagActionTest.class);
public void testCreateTagFail() throws Exception {
logger.debug("Entering testCreateTagFail()");
try {
request.setParameter("name", "");
ActionProxy proxy = getActionProxy("/createtag.action");
TagAction tagAction = (TagAction) proxy.getAction();
proxy.execute();
assertTrue("Problem There were no errors present in fieldErrors but there should have been one error present", tagAction.getFieldErrors().size() == 1);
assertTrue("Problem field 'name' not present in fieldErrors but it should have been",
tagAction.getFieldErrors().containsKey("name") );
} catch (Exception e) {
logger.debug("Error running testCreateTagFail()");
e.printStackTrace();
assertTrue("Error running testCreateTagFail()", false);
}
}
Partial stack trace:
java.lang.NullPointerException
at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
Lastly, can anyone explain what the deal is with StrutsTestCase? There's a tutorial page for using it with Struts 2 on struts.apache.org but the SourceForge page for it hasn't been updated since Struts 1.3 Also, what's the difference between StrutsTestCase and MockStrutsTestCase
I imagine you're initialising tiles with a listener:
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
You need to initialise that Listener in your tests. I found a few others with the same issue [1].
The code below is in your class that extends StrutsSpringTestCase. You need to override the setupBeforeInitDispatcher. In the code snippet below, the override sets the applicationContext attribute (also needed if you're using spring) and initialises Tiles (inside the if(tilesApplication) segment, where tilesApplication is a boolean so you can toggle this code on an off based on your whether or not your application runs with tiles ):
/** Overrides the previous in order to skip applicationContext assignment: context is #autowired
* #see org.apache.struts2.StrutsSpringTestCase#setupBeforeInitDispatcher()
**/
#Override
protected void setupBeforeInitDispatcher() throws Exception {
//init context
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
if(tilesApplication){
servletContext.addInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG, "WEB-INF/tiles.xml");
final StrutsTilesListener tilesListener = new StrutsTilesListener();
final ServletContextEvent event = new ServletContextEvent(servletContext);
tilesListener.contextInitialized(event);
}
}
[1] See http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/
It is trying to display the jsp page. So disable by adding ExecuteResult(false) in the code.
So, add the below line
proxy.setExecuteResult(false);
before proxy.execute()