Problema con NullPointerException

Aca esta mi problema: la idea es que cuando le de click al cuadrado se cambie de imagen, pero no sucede nada.
String estado;

PImage castilloM;
PImage castilloM2;
PImage charla2;
PImage jhon;
PImage dama;
PImage cuadrado;

void setup(){
size (800, 600);

//imagenes
castilloM =loadImage( “castilloM.jpg”);{
castilloM2 = loadImage ( “castilloM2.jpg” );
jhon = loadImage ( “jhon.png” );
dama = loadImage ( “dama.png” );
cuadrado = loadImage ( “cuadrado.jpg” );

estado = 0

}

void draw (){

if( estado.equals(“0”) ){
background (castilloM);

image (cuadrado, 50, 170, 100, 200);

}else if ( estado.equals(“castillo”) ){
image ( castilloM2, 0, 0, 400, 400 );

}
}

void mousePressed (){

fill (150);
rect( 150, 250, 100, 50 );
if ( mouseX > 145 && mouseX < 155 && mouseY > 155 && mouseY < 165){

estado = “castilloM”;

Hi @Francesco,

Welcome to the community! :slight_smile:

Please format your code using the </> button.
From the code that you posted I can only see that you are changing estado to “castilloM”, but in draw() you are only checking if estado is equal to “0” or “castillo”. That might be the reason why is not changing anything.

A small tip: You might want to consider loading the images to an array (https://www.youtube.com/watch?v=DPFJROWdkQ8)
Thus, when pressing the mouse click you only need to change a variable that tells the index of the array on the image to be drawn.

:O, Muchas gracias, era eso!!! me salvaste