Nifty.addxml AssetNotFoundException

Hi guys,

I am having an issue with JME and nifty. For whatever reasons, my application behavior changed in the last days and I have no clue what happened or how I can fix it.

Scenario:

  • I have a start screen in the sub-directory of my projects (\assets\Interface\Nifty\Screens\start.xml)
  • During my simpleInit()-Method of my main application, I execute the nifty registration and the addXML() command
  • However, this addXML()-Method call (nifty.addXml("Interface\\Nifty\\Screens\\start.xml"); ) leads to an AssetNotFoundExecption, if I do not explicitly execute the following code before:

assetManager.registerLocator(System.getProperty("user.dir") + File.separator + "assets" + File.separator, FileLocator.class);

Exception:

java.lang.RuntimeException: com.jme3.asset.AssetNotFoundException: Interface\Nifty\Screens\start.xml
	at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:663)
	at de.lessvoid.nifty.Nifty.addXml(Nifty.java:603)


Caused by: com.jme3.asset.AssetNotFoundException: Interface\Nifty\Screens\start.xml
	at com.jme3.niftygui.NiftyJmeDisplay$ResourceLocationJme.getResourceAsStream(NiftyJmeDisplay.java:85)
	at de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader.getResourceAsStream(NiftyResourceLoader.java:69)
	at de.lessvoid.nifty.Nifty.getResourceAsStream(Nifty.java:2017)
	at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:651)
  • I do not know why this is necessary, but it seemed to work (the months before, I did not have the issue and it worked without these code line)

  • Anyway, I thought this small fix might be OK, but when I create an .exe file from my project and put this to my project’s root directory, I get a similar error (but referring to nifty-default-styles.xml)

image

Both things worked before without any issues (addXML()-call without this weird coding line and executing the application from an EXE file in the project’s root.

I’m using IntelliJ IDE. Might this issue be related to any java classpath settings? I have to admit that I’m not an advanced java developer. It’s more a kind of hobby.

Thanks

assetManager.registerLocator(System.getProperty("user.dir") + File.separator + "assets" + File.separator, FileLocator.class);

This line is necessary unless your build script adds the assets jar automatically. The only directory that works by default is the src/main/resources directory. The engine itself hasn’t changed anything relating to this, so your code must have changed as such that that line is executed too late now.

Just add it to your simpleInitApp method or amend your build script if you changed it.

1 Like

Thanks for the answer. Good to know, that at least the code line is correct.

Actually, it is currently the very first line of my simpleInitApp() method. My (maybe wrong) assumption was, that an .exe-file in the project directory should work the same way, the code works when starting it in my IDE, isn’t it? (because the directory / path is absolutely the same?)

So, with this line existing in the simpleInitApp, I can start the application. But it doesnt work with a “converted” .exe file.

And yes, I know that JME hasn’t changed anything and that the cause of the problem sits in front of the monitor. However, if the software will be used on another system environment later on, I need a working .exe file. :slight_smile:

As mentioned, I’m not the biggest expert. I do not even know what a build script is. But I don’t want to exclude that I changed it during a night shift session.

I was also thinking to create a complete new project and copy & paste the code there. Not sure whether this solves my issue at all. :slight_smile:

The assets directory is usually only used during development. (And those of us who are purists never use it and will always use the assets.jar even during development.)

Generally, most normal JME build scripts will bundle the assets into an assets.jar and make that a dependency of the application, ie: part of its classpath.

So whenever I hear errors of the type “It runs in the IDE but not when I run it as an application” that usually indicates to me that the “application building” process did not make an assets.jar as part of the app.

1 Like

Hi,

thanks for the answer. I do have a kind of model-view-control approach, so JME is just one part of my whole architecture. However, I re-created the artifacts in my IDE, so I created a completely new .jar file of my project (by IntelliJ standard tools). So, I do have one .jar file for my project (i.e. no assets.jar). Converting this to an .exe, it works again, for whatever reasons. :slight_smile:

As mentioned, I’m not an expert in java and I’m not really knowing what I’m doing. But it seems to work again somehow.

Thanks