AssetLoadException

What different betwean

Material material = new Material(assetManager, "Materials/MyCustomRocksMaterial.j3m");
sphereGeo.setMaterial(material);
rootNode.attachChild(sphereGeo);

and

sphereGeo.setMaterial(assetManager.loadMaterial("Materials/MyCustomRocksMaterial.j3m"));
rootNode.attachChild(sphereGeo);

Second variant works great unlike first which throw AssetLoadException whith next stackTrace:

com.jme3.asset.AssetLoadException: An exception has occured while loading asset: Materials/MyCustomRocksMaterial.j3m
	at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:261)
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:373)
	at com.jme3.material.Material.<init>(Material.java:108)
	at BollExpertDesktopView.simpleInitApp(BollExpertDesktopView.java:88)
	at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:220)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:211)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Material instances must be loaded via MaterialKey
	at com.jme3.material.plugins.J3MLoader.load(J3MLoader.java:753)
	at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:259)
	... 7 more

This is wrong because the second parameter in the Material constructor has to be a Material Definition instead of a Material (as you’re trying to use).

Read this
http://javadoc.jmonkeyengine.org/com/jme3/material/Material.html
And this
https://jmonkeyengine.github.io/wiki/jme3/beginner/hello_material.html

3 Likes