i’ve tried loading a picture for my GUI using the HUD Tutorial,
but it always crashes with the following error:
com.jme3.asset.AssetLoadException: An exception has occured while loading asset: Common/MatDefs/Gui/Gui.j3md
Caused by: java.io.IOException: Material instances must be loaded via MaterialKey
Can you give a link to the tutorial and the relevant part of your code?
either the tutorial is outdated, or you do something wrong, but cannot tell from here.
Well, it seems like you kind of do things different than the tutorial so there are problems with your approach. Now that we can finally see the code… like, why do you set your own material?
No idea, I just want to load the picture. I think I read it somewhere and tried it after the Tutorial didn’t work. Would be awesome if someone could tell me how to properly load a picture.
It gives me the error which I wrote in my original post. This forum is as helpful as the stupid Tutorial… I can’t just guess what causes the error if there’s documentation for it. It’s not like I didn’t try to google it first. Do me a favor and read the whole post before giving me anymore of these answers.
Material mat = assetManager.loadAsset(new MaterialKey("Common/MatDefs/Gui/Gui.j3md"));
that should be
Material mat=new Material(assetManager,“Common/MatDefs/Gui/Gui.j3md”);
EDIT:
I read your code more carefully and the problem is that you don’t have to set a material at all (like you do in this line: picture.setMaterial(mat);).
Look at the source code here when you call setTexture it already creates the material.
@Navalon said:
It gives me the error which I wrote in my original post. This forum is as helpful as the stupid Tutorial... I can't just guess what causes the error if there's documentation for it. It's not like I didn't try to google it first. Do me a favor and read the whole post before giving me anymore of these answers.
I can only comment on the code that you actually show us. And saying “I based it on the tutorial” and then showing us totally different code… it’s impossible for us to guess what might or might not have been done wrong.
So, yes, if all you post is “I got this problem”… then you will get a wide variety of less than helpful answers.
I’m done with this thread and will let other people help you instead. I’ve exceed my personal limit to back-and-forth. However, it would help other people if you actually post code with the problems, explain which version of JME you are using, etc… when in doubt, give TOO MUCH information… instead of hardly any information. Otherwise, the forum will be no better than googling.
@Riccardo said:
I think that the problem is this line
Material mat = assetManager.loadAsset(new MaterialKey("Common/MatDefs/Gui/Gui.j3md"));
that should be
Material mat=new Material(assetManager,“Common/MatDefs/Gui/Gui.j3md”);
EDIT:
I read your code more carefully and the problem is that you don’t have to set a material at all (like you do in this line: picture.setMaterial(mat);).
Look at the source code here when you call setTexture it already creates the material.
Thank you for your answer. I tried to use exactly the code in the tutorial:
com.jme3.asset.AssetLoadException: An exception has occured while loading asset: Common/MatDefs/Gui/Gui.j3md
Caused by: java.io.IOException: Material instances must be loaded via MaterialKey
then I have tried pic.setTexture instead of setImage:
com.jme3.asset.AssetLoadException: An exception has occured while loading asset: Common/MatDefs/Gui/Gui.j3md
Caused by: java.io.IOException: Material instances must be loaded via MaterialKey
then I have tried pic.setTexture instead of setImage:
which gives me the same error. I hope you understand what I’m trying to say.
The code you have posted here is correct and it works properly with the latest stable release of jme3 sdk.
So, maybe the problem is with your installation or somewhere else in your code. Try to do a new SimpleApplication with just