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?

thx


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();
        modeloNode.attachChild(modelo);
        rootNode.attachChild(modeloNode);
        
        control = modelo.getControl(AnimControl.class);
        channel = control.createChannel();
        //channel.setAnim("inicial");
        
        Ojo_der_mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
        Ojo_der_mat.setBoolean("UseMaterialColors",true);
        Ojo_der_mat.setColor("Ambient", ColorRGBA.White);
        Ojo_der_mat.setColor("Diffuse", ColorRGBA.White);
        Geometry Ojo_der = (Geometry) modeloNode.getChild("Ojo_der");
        Ojo_der.setMaterial(Ojo_der_mat);
        
        Ojo_izq_mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
        Ojo_izq_mat.setBoolean("UseMaterialColors",true);
        Ojo_izq_mat.setColor("Ambient", ColorRGBA.White);
        Ojo_izq_mat.setColor("Diffuse", ColorRGBA.White);
        Geometry Ojo_izq = (Geometry) modeloNode.getChild("Ojo_izq");
        Ojo_izq.setMaterial(Ojo_izq_mat);
        
        Ojo_der_mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/abierto.png"));
        Ojo_izq_mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/abierto.png"));
        //Animar("inicial");
        Ojo_der();
    }
    void Animar(String animacion){
        channel.setAnim(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 http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html 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

This:
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.