Weird NullPointerException on a material

Hi, im sure this is a stupid question but dont have any idea of what it could be

im trying to change a material texture trough a method, I first set it in the constructor with no problem, but when i call it from the “Ojo_der” method just throw me a NullPointerException, i dont have any idea of why, any help with this please?


package mygame;

import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

 * @author Willer
public class Bicho {
    public Spatial modelo;
    public Node modeloNode;
    private AnimChannel channel;
    private AnimControl control;
    public Material Ojo_der_mat;
    AssetManager assetManager;
    Material Ojo_izq_mat;

    Bicho(AssetManager assetManager,Node rootNode){
        modelo = assetManager.loadModel("Models/Adan.j3o");
        modeloNode = new Node();
        control = modelo.getControl(AnimControl.class);
        channel = control.createChannel();
        Ojo_der_mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
        Ojo_der_mat.setColor("Ambient", ColorRGBA.White);
        Ojo_der_mat.setColor("Diffuse", ColorRGBA.White);
        Geometry Ojo_der = (Geometry) modeloNode.getChild("Ojo_der");
        Ojo_izq_mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
        Ojo_izq_mat.setColor("Ambient", ColorRGBA.White);
        Ojo_izq_mat.setColor("Diffuse", ColorRGBA.White);
        Geometry Ojo_izq = (Geometry) modeloNode.getChild("Ojo_izq");
        Ojo_der_mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/abierto.png"));
        Ojo_izq_mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/abierto.png"));
    void Animar(String animacion){
    void Ojo_der(){
        Ojo_der_mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/abierto.png"));
    void Ojo_izq(String ojo){
        //Ojo_izq_mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/" + ojo + ".png"));

Put java in the square brackets not code and it should format better.

Please read and follow it makes it MUCH easier for experienced java devs to follow your code.

You will have a warning in the SDK at this line inside your constructor:
Material Ojo_der_mat = new Material(assetManager,“Common/MatDefs/Light/Lighting.j3md”);

Read the warning. It’s there for a reason. Fix it and you will fix your problem.

Thanks for the reply, first my english is not very usefull so ¿how do I do the square brackets thing?
Thanks for the oracle link too, if youre talking about the indentation im using it, but dont have any idea as said befor of what to do to show them.
And for the reply, first, youre brilliant, I removed the “Material” from the line cause it was causing a warning, buuut didnt solve anything

Any more help? Thanks so much

And sorry for my english

AssetManager assetManager;

…is null. You never set it.

Just saying: stepping through the code in a debugger or adding some logging probably would have shown this in the amount of time it took to write the original post.

Ahh yes, there was a second error there too. Well spotted pspeed.

@willer I mean things like the naming conventions on things like variables, classes, etc. It makes it much easier to read your code if I can see immediately what things are because they follow the style conventions.

As pspeed says though null pointer exceptions are generally easy to track down. Just user the debugger or add debug statements and you should be able to track them down.