Null Pointer Exception Fun With "Hello Asset" Tutorial

In the Hello Asset tutorial, as part of the exercise (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_asset#excercise_-_how_to_load_assets) it tells you to download the town.zip file, place it in your root folder (which I did) and then just add the code given.



Fun times for all! Except that I get a Null Pointer Exception when I try to load the ā€œmain.sceneā€ model, at the line Spatial gameLevel = assetManager.loadModel(ā€œmain.sceneā€);



So I thought, maybe zips just hate me. Or maybe I have mistaken the directory that my program runs from.



So, I unzipped everything and then used a FileLocator and explicitly gave the path to the town folder. Yet another NPE.



So uh, am I using a bad build or something? Is there something special Iā€™m missing?

No, I think youā€™re doing something wrong :slight_smile: Any more info?

Same question as here, interestingly enough: http://hub.jmonkeyengine.org/groups/general-2/forum/topic/helloassets-assetmanager-loadmodel-error/



Iā€™m not alone!



What more information do you want? I copy pasted code directly from the tutorial. The basic stuff worked perfect, but the part with the assetManager and custom paths did not, directly copy pasted and the instructions followed exactly.



Windows 7, 64 bit, 8gb ram, no anti virus problems (turned it off while testing just to see if maybe it did something; it didnt), donā€™t know what else to say. Using Eclipse and the jME3_10-05-2010 build.



Perhaps some kind of mod could merge this topic and http://hub.jmonkeyengine.org/groups/general-2/forum/topic/helloassets-assetmanager-loadmodel-error/ ? They are the same error.

ZipLocator and file loading works fine, youā€™re doing something wrong I tell you :wink:

The start path of your project when you run it in the IDE is the project root folder, when you run the distribution jar file its the dist directory.

Cheers,

Normen

I exported the project as jar and ran it within the same directory as town.zip, it still failed.



However, http://hub.jmonkeyengine.org/groups/general-2/forum/topic/helloassets-assetmanager-loadmodel-error/ got me a solution: put the chunk

Code:
assetManager.registerLocator("town.zip", ZipLocator.class.getName()); Spatial gameLevel = assetManager.loadModel("main.scene"); gameLevel.setLocalTranslation(0, -5.2f, 0); gameLevel.setLocalScale(2); rootNode.attachChild(gameLevel);

BEFORE the ninja model code chunk.

Why did this fix it? I don't understand.

ā€¦ well easy, without the locator the AssetManager cant locate stuff :stuck_out_tongue:

Happy you got it to work,

Normen

I don t understandā€¦ the ā€œassetManager.registerLocatorā€ was already present beforeā€¦

I did not see any code in this thread, you are referring to your problem? That seems to be another issue, yes. Guess some caching thing or something. Maybe @Momoko_Fan knows moreā€¦

Alright, to be more specific, THE FOLLOWING CODE WORKS:



http://pastebin.com/ETh6HHtB



The following code DOES NOT WORK:



http://pastebin.com/gS0Pmgfx



The only difference is that this code:

Code:
//load town! assetManager.registerLocator("town.zip", ZipLocator.class.getName()); Spatial gameLevel = assetManager.loadModel("main.scene"); gameLevel.setLocalTranslation(0, -5.2f, 0); gameLevel.setLocalScale(2); rootNode.attachChild(gameLevel);

Is placed before or after this code:
Code:
// Load a model from test_data (OgreXML + material + texture) Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml"); ninja.scale(0.05f, 0.05f, 0.05f); ninja.rotate(0.0f, -3.0f, 0.0f); ninja.setLocalTranslation(0.0f, -5.0f, -2.0f); rootNode.attachChild(ninja);

If it is after the code, the program will crash. If it is before, the program works as intended.

My question is WHYYYYYY?

(Sorry for pastebinning the two examples - the site wasn't letting me post that long of a post.)
normen said:
That seems to be another issue, yes. Guess some caching thing or something. Maybe @Momoko_Fan knows more..

I think the ZipLocator might be returning an AssetInfo even if thereā€™s no such file in the zip, in that case, it is a bug.