Problem with model import

Hi i wrote my own model import class (actually the code is nearly completely copied from HelloModelLoading) but for som reason it doesnt work:


public class ModelLoader{
   public ModelLoader() {
      
   }
public Node importModel(String location) {
      Node model = null;
      
      URL modelURL=ModelLoader.class.getClassLoader().getResource(location);

        FormatConverter converter=new ObjToJme();
      
        converter.setProperty("mtllib",modelURL);

        ByteArrayOutputStream BO=new ByteArrayOutputStream();
        try {
            converter.convert(modelURL.openStream(), BO);
            model=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            model.setModelBound(new BoundingSphere());
            model.updateModelBound();
        } catch (IOException e) {   // Just in case anything happens
            System.out.println("Modelload faild");
            System.exit(0);
        }
        return model;
   }
}



i get a nullpointerexceptionin this line:

converter.convert(modelURL.openStream(), BO);


for somereason the URL isnt created correctly and i suppuse that i made a newbish mistake with the location path so her is my structure:
My Game Folder
-pakage1 // here is the class where model loader is created and importModel is called
-pakage2 // here is my ModelLoader class
-models  //in this  Folder is the .obj and .mtl file
i call importModel with "models/model.obj"

btw i am using jme 1.0

I had this problem too, it has a simple solution.



Change ModelLoader.class.getClassLoader().getResource(location); to simply ModelLoader.class.getResource(location);



Also, make sure everything is case sensitive!

thx for the fast reply although it doesnt help :confused:



and what do you mean with: Also, make sure everything is case sensitive ?

Can you show us the stack trace?

Exception in thread "main" java.lang.NullPointerException
at MyUtils.ModelLoader.importModel(ModelLoader.java:49)
at MyGamePackage.Player.loadPlayerModel(Player.java:61)
at MyGamePackage.Player.initPlayer(Player.java:46)
at MyGamePackage.Player.<init>(Player.java:37)
at MyGamePackage.WorldState.<init>(WorldState.java:27)
at MyGamePackage.MyGameClass.createGameStates(MyGameClass.java:42)
at MyGamePackage.MyGameClass.<init>(MyGameClass.java:31)
at MyGamePackage.MyGameClass.main(MyGameClass.java:21)

line 49 is the one i told u

make sure that your model folder is marked as a source folder in your IDE.

(it needs to be added to the classpath. to be able to find the resources)

Ok somhow it works now.

Change ModelLoader.class.getClassLoader().getResource(location); to simply ModelLoader.class.getResource(location);

this tip was crap for me - it creats an additional nullpointer exception cause the URL isnt created correctly

thanks for the tipp with the source folder although for some reason it doesnt have to be a sourcefolder but a package in eclipse. I noticed this when ai took a look in the jme project