Here I am again. Now my problem is with .obj loading.
Using the code of the tutorial HelloModelLoading (which works and show me lisa perfectly) I've tried to load an obj that i've made with sketcUp Pro. The result is:
GRAVE: Exception in game loop
java.lang.NullPointerException
at primaProva.simpleInitGame(primaProva.java:44)
at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at primaProva.main(primaProva.java:28)
the source code is:
// Point to a URL of my model
URL model = primaProva.class.getClassLoader().getResource("/provaJME/src/data/PianoTerra.obj");
// Create something to convert .obj format to .jme
FormatConverter converter = new ObjToJme();
// Point the converter to where it will find the .mtl file from
converter.setProperty("mtllib", model);
// This byte array will hold my .jme file
ByteArrayOutputStream BO = new ByteArrayOutputStream();
try {
// Use the format converter to convert .obj to .jme
converter.convert(model.openStream(), BO);
Node maggie = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
// shrink this baby down some
maggie.setLocalScale(.1f);
maggie.setModelBound(new BoundingSphere());
maggie.updateModelBound();
// Put her on the scene graph
rootNode.attachChild(maggie);
} catch (IOException e) { // Just in case anything happens
System.out.println("Damn exceptions!" + e);
e.printStackTrace();
System.exit(0);
}
Debugging with eclipse i've found that the problem is that the following line of code:
URL model = primaProva.class.getClassLoader().getResource("/provaJME/src/data/PianoTerra.obj");
return null and so the conversione to jme fail for java.lang.NullPointerException.
I've tried changing the path and the folder of my obj but it still doesn't work.
Why it don't "catch" my obj??? What can i do???
Sorry for my bad English!!!
- welcome
- don't use multiple exclamation marks!
- Class names always have to begin with an upper case letter in Java :x (PrimaProva)
- try it with these paths:
"provaJME/src/data/PianoTerra.obj"
"src/data/PianoTerra.obj"
"data/PianoTerra.obj"
NOTE: none of them must have the slash at the beginning!
Thx for your help! Now it's working! Next time I'll not use multiple exclamation marks! For the upper case letter forgive me but I'm back to Java after a 5 month of C++!!