Java.lang.NullPointerException when loading model

Hi Folks,

    Love the work done here. Thanks so much for being willing to share. Let me first say that I am NOT trying to create a game. (not yet at least). This is all for learning the ins and outs for me. I am a 14 year programming vet, but this is my first foray into graphics. So, theres the background on my newness.

Anyway, I am trying to load a model and the format is .obj, exported from blender. My failure happens here

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

So, my files are found correctly, but I get that java.lang.NullPointerException. I have searched and played around for days, but to no avail. Hence, my first question! I would appreciate it anyone could tell me whats wrong. I am using the flagrush tutorial as my basis for this learning tool.

       Spatial st = null;
        URL modele=Lesson8.class.getClassLoader().getResource("jmetest/rtsdemo/data/runman.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
        // This byte array will hold my .jme file
        ByteArrayOutputStream BO=new ByteArrayOutputStream();
            // Use the format converter to convert .obj to .jme
            converter.convert(modele.openStream(), BO);
            st=(Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            // shrink this baby down some
            st.setModelBound(new BoundingBox());
        } catch (IOException e)
        {   // Just in case anything happens

Thanks for any help that can be offered.

So how about a little simple help. That file IS in that directory, so why would it be null?

Thanks for any help.


I am having the same problem when setting it up on my laptop however at university it works fine. I solved it the first time around but cannot remember how. All I can say is try having complete class paths say C:/… or C:…\ Also, its not that noone wants to help but its saturday early morning so probably most people are in bed  XD

i created the package, copied maggie.obj there and it loaded fine with your code.

i guess something is wrong with your projects setup.

are you using eclipse or something else?

I got it!! Its probably the same mistake that I made the first time and took ages realizing it - you have put the runman.obj file in the srcjmetestdatamodel instead of jmebuildjmetestdatamodel. This should solve your problem. Have fun!

I am using eclipse and unfortunately my item IS in the srcjmetestdatamodel folder! Any other thoughts? Thanks for taking a look folks.


I just  rebuilt the package from scratch and it worked. Not sure what the problem was, but it worked fine. Thanks for taking a look…

When you add a new file into a package or directory in eclipse, you need to manually refresh this folder.

I've run a few times into this problem already.