Okay, I had my lil class to load 3d objects into jme and for a time, it was good. Recently I moved from netbeans 5.5 to 6. and installed jme2 instead of 1, and it stopped working all of sudden.
I have 3ds file in my source package, I tried putting it everywhere, and still I keep getting null pointer exception, I am sure that I am doing something bad, and it is probably obvious, as all my previous mistakes, but I really can't find anything…
Code:
(System.out.println(url); returns null which means it cannot find file, but why? I even tried providing locator with direct link to it and still nothing.)
public static void load(String name, Node rootNode)
{
MaxToJme maxtojme = new MaxToJme(); //the converter
Node node = null; //Where to dump mesh.
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); //For loading the raw file
// File Path for the model (dump file in toplevel of classpath)
URL url = truck.class.getClassLoader().getResource(name);
System.out.println(url);
InputStream is=null;
try {
is=url.openStream();
} catch(Exception err) {
System.out.println("Could not open Model file: "+err);
}
try {
// Converts the file into a jme usable file
maxtojme.convert(is, bytearrayoutputstream);
// Used to convert the jme usable file to a TriMesh
BinaryImporter binaryImporter = new BinaryImporter();
ByteArrayInputStream in=new ByteArrayInputStream(bytearrayoutputstream.toByteArray());
//importer returns a Loadable, cast to Node
node = (Node)binaryImporter.load(in);
} catch(Exception err) {
System.out.println("Error loading model:"+err);
}
//attach node to scene graph
node.updateRenderState();
}
And error:
2008-11-25 22:58:39 class truck.Main start()
SEVERE: Exception in game loop
java.lang.NullPointerException
at truck.Main.load(Main.java:81)
at truck.Main.simpleInitGame(Main.java:132)
at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:527)
at com.jme.app.BaseGame.start(BaseGame.java:71)
at truck.Main.main(Main.java:89)
Thanks.