NullPointerException when using assetManagerloadAsset

I am trying to use assetManager.loadAsset to access png files to use as icons for my program. However, I keep getting a NullPointerException on the lines where I do so. Is my path wrong, or can I simply not use assetManager for this?

This is where my Icons folder with the images is:

I am still somewhat new to jme3, so please bear with me if this is a stupid question.
(Also: I was using ClassLoader to load the images earlier but had complications with the images’ library folder being deleted when I made the project’s jar with Clean and Build - but thats a whole other issue)

Is this being called before the app is started? The asset manager isnt running if the app hasnt started. I cant remember off the top of my head but i believe you use the classloader and to load icons. At work so i dont have the correct code in front of me.

You were having trouble with the folder, put the icons in a package on your classpath not in assets

1 Like

Pretty sure that JME will not load images… only textures. I could be wrong but I’ve never needed to use JME to load images directly (Java can already do that just fine in one call.)

And as mentioned, JME is not running enough to load these as icons for your application icon… you will have to use the regular Java approach for loading class resources."/Interface/Icons/blah blah"));

1 Like

Thanks, that’s what I suspected the issue was. I was able to get classLoader working for my icons only to an extent. When I built the JAR file with the “Clean and Build,” the folder I stored the image files in got deleted because the IDE said:

Not copying library D:\Documents\Java Game Projects\BasicGame\build\resources , it can’t be read.

I couldn’t find any forum posts or documentation as to why it deletes the folder - maybe I’m supposed to be placing the folder elsewhere or as a package(?). Let me know if you know the answer. Maybe I should delete this post and make a new one regarding the folder deletion issue.

Thanks, I’ll give it a shot. This is a ton of help

“build” is the target. Every time you clean, “build” will be removed. Don’t ever put sources there.

Wow ok I had no idea what I was doing ealier (honestly, I still dont completely). I followed your instructions but was still having trouble getting the images included in the build. The last thing I tried was adding a package of the images in Source Packages - somehow it works! Thanks for your help

All you had to do was leave the images in the assets folder and my code would have loaded them. The assets are already packaged for you.