My method loads some pictures and some not :(

Hai!

I got this function that loads images.

The problem is that, nomather what I do, it refuse to load my other picture:

tree.jpg



I dont know whats wrong with it, it says:

2010-jan-06 21:33:03 com.jme.util.resource.ResourceLocatorTool locateResource
VARNING: Unable to locate: tree.jpg
java.lang.NullPointerException
        at hello3d.test.ModelnTexture.getModel(ModelnTexture.java:69)


line 69 is this:

textureR = new URL(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, tex).toURI().toString());


and heres the whole code:

URL textureR;
        try {
            ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, new SimpleResourceLocator(HelloWorld.class.getResource("/data/textures/").toURI()));
            textureR = new URL(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, tex).toURI().toString());
            System.out.println(textureR);
            texture.setTexture(TextureManager.loadTexture(textureR,Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear,1.0f,true));
            texture.setEnabled(true);
            texture.setTextureCoordinateOffset(0);
            //System.out.println(textureR);
            node.setRenderState(texture);
            node.updateRenderState();
            node.setModelBound(new BoundingBox());
            node.updateModelBound();
            //node.setRenderState(materialState3);
        } catch (Exception ex) {
            ex.printStackTrace();
        }



the pictures I load is "ammoBoxTex.jpg" , "tree.jpg" (this one doesnt work) , "ground.jpg"

I load all the exact same way, got em all in exact same directory still it doesnt work!

Please help, I'v been debugging for hours but havn't got a clue why it doesnt work  :'(

Have you triple checked the spelling in all places?

Updated your project if you use Eclipse?

As you load them the exact same way, it seems like the image is really not there or the name is slightly wrong somewhere.



This line here is unnecessarily complicated:

textureR = new URL(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, tex).toURI().toString());



locateResource gives you a URL so you really only need to do this:

textureR = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, tex);



Also, you only need to do this line once, otherwise you add the same location several times:

ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, new SimpleResourceLocator(HelloWorld.class.getResource("/data/textures/").toURI()));

Okej, So I updated it, made a set method that do this line:

ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, new SimpleResourceLocator(HelloWorld.class.getResource("/data/textures/").toURI()));


and run the set method only once.

I also changed the other line, and now it's better.
Instead of getting the error, I simple get textureR = null.
Which is better :)
but still... :|

I know, i'v copied the names of the file into the method call, done everything..
But the texture still says it's null :(

YEAS!!!

I found out that the directory it was actually looking in was:

NetBeansProjectsHello3Dbuildclassesdatatextures

not

Hello3Dsrcdatatextures

and once putting my image in the correct folder it worked out!!

JIIPIII!!!  :smiley:



Thanks again tumaini for the help, it was real usefull, I like you :slight_smile: