AssetNotFoundException when loading nifty definitions from XML file

Hi,



I get an AssetNotFoundException when loading the nifty definitions from an XML file. The stack trace looks like this:

[java]com.jme3.asset.AssetNotFoundException: assets/Interface/jump_n_run.xml

at com.jme3.niftygui.NiftyJmeDisplay$ResourceLocationJme.getResourceAsStream(NiftyJmeDisplay.java:77)

at de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader.getResourceAsStream(NiftyResourceLoader.java:65)

at de.lessvoid.nifty.Nifty.getResourceAsStream(Nifty.java:1581)

at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:527)

at de.lessvoid.nifty.Nifty.fromXml(Nifty.java:438)

…[/java]



As far as I can see, the file content doesn’t even matter. I tried with different files, and even the "Hello World"s from different tutorials produce the error, so I assume it’s something with the resource management.



The file lies in the given subfolder and can be accessed in other ways. Also, the following methods are used:

[java]assetManager.registerLocator(“assets”, FileLocator.class);

assetManager.registerLoader(XMLImporter.class, “xml”);[/java]



We also load textures via the asset manager, from the subfolder “assets/Textures/”, and that is working fine.



Eclipse is used, with the classpath looking like this:

[xml]<classpath>

<classpathentry kind=“src” path=“src”/>

<classpathentry kind=“con” path=“org.eclipse.jdt.launching.JRE_CONTAINER”/>

<classpathentry kind=“lib” path=“lib/eventbus.jar”/>

<classpathentry kind=“lib” path=“lib/j-ogg-oggd.jar”/>

<classpathentry kind=“lib” path=“lib/j-ogg-vorbisd.jar”/>

<classpathentry kind=“lib” path=“lib/jbullet.jar”/>

<classpathentry kind=“lib” path=“lib/jinput.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-blender.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-core.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-desktop.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-effects.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-jbullet.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-jogg.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-lwjgl-natives.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-lwjgl.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-networking.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-niftygui.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-plugins.jar”/>

<classpathentry kind=“lib” path=“lib/jME3-terrain.jar”/>

<classpathentry kind=“lib” path=“lib/lwjgl.jar”/>

<classpathentry kind=“lib” path=“lib/nifty-default-controls.jar”/>

<classpathentry kind=“lib” path=“lib/nifty.jar”/>

<classpathentry kind=“lib” path=“lib/stack-alloc.jar”/>

<classpathentry kind=“lib” path=“lib/vecmath.jar”/>

<classpathentry kind=“lib” path=“lib/xmlpull-xpp3.jar”/>

<classpathentry kind=“output” path=“build/classes”/>

</classpath>[/xml]



I checked the tutorials, but the jME-Tutorial only tells how to use assets like textures (which is working), and the nifty tutorial doesn’t talk about the asset manager, because it’s not part of the nifty gui.



An older version of both jME and Nifty (early 2011 I think) were used previously, and after updating and fixing compiler errors and adjusting to the “new timing”, we still have trouble with the assets.

Does anybody see why the asset manager does not load the file?

Most of your post is irrelevant at this point. What’s the code to load the XML? Of particular interest is fromXml line.

[java]private void initGui() {

AssetManager assMan = game.getAssetManager();

InputManager inpMan = game.getInputManager();

AudioRenderer audRend = game.getAudioRenderer();

ViewPort viewPort = game.getGuiViewPort();

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assMan, inpMan, audRend, viewPort);

nifty = niftyDisplay.getNifty();

game.getGuiViewPort().addProcessor(niftyDisplay);



// load GUI from XML file

JumpRunScreenController controller = new JumpRunScreenController(game, nifty);

nifty.fromXml(xmlPathJumpRun, startScreenName, controller);

nifty.addXml(xmlPathSettings);

}[/java]



That’s the method that involves the fromXML method. The variables contain the relative file path (in this case “assets/Interface/jump_n_run.xml”, as seen in the error message) and the name of the start screen. Both are read from a property file.



The variable “game” is an instance of Application.

Remove “assets” in your path. It should be “Interface/jump_n_run.xml”.

I see the problem now. I wonder why it didn’t work when I tried that before. But it does now, so I probably didn’t see it because of another error that I made during the debugging.

Thank you :slight_smile:

try this : nifty.fromXml(“Interface/Nifty/HelloJme.xml”, “start”);

that will implicitly create a controller, which is not what he wants, and the issue is already resolved :stuck_out_tongue: