Texture problem

I'm trying to move from jme2 to jme3, but it is too confusing for me. I trying to render a box with a simple texture:


package jme.classes;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        Box b = new Box(Vector3f.ZERO, 10, 1, 10);
        Geometry geom = new Geometry("Box", b);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
        mat.setTexture("m_ColorMap", assetManager.loadTexture("texture.jpg"));
        geom.setMaterial(mat);
       
        rootNode.attachChild(geom);
    }

    @Override
    public void simpleUpdate(float tpf) {
       
    }

    @Override
    public void simpleRender(RenderManager rm) {
       
    }
}



I get this error:

WARNING DesktopAssetManager 14:48:22 Cannot locate resource: texture.jpg
SEVERE Application 14:48:22 Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
        at com.jme3.material.Material.setTexture(Material.java:240)
        at jme.classes.Main.simpleInitApp(Main.java:22)
        at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:141)
        at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:102)
        at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)
        at java.lang.Thread.run(Thread.java:619)
Java Result: -1073741819


The first line says that can't locate the texture, but it is in the same folder as Main.java.
Maybe I just confused or it is a bug. I was in doubt if I should stay with jme2 or try jme3.

Hope you guys could help me.

You have to specify the whole classpath to the texture. So when your main is in com.mygame.Main.java it would be /com/mygame/texture.jpg

And if i want to put it on the assets? How am  suppossed to do?

GustavoBorba said:

And if i want to put it on the assets? How am  suppossed to do?

Put it in /assets/Textures/texture.jpg and then load it with assetManager.loadTexture("assets/Textures/texture.jpg")

The code for, pretty much, exactly what you are trying to do is available in the third jME3 tutorial under the Loading Textures section.

Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
mat.setTexture("m_ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
geom.setMaterial(mat);
rootNode.attachChild(geom)