# Problema con NullPointerException

**URL:** <https://discourse.processing.org/t/problema-con-nullpointerexception/22349>\
**Category:** Español\
**Tags:** homework\
**Created:** [July 3, 2020, 7:11am UTC](https://discourse.processing.org/t/problema-con-nullpointerexception/22349 "2020-07-03T07:11:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francesco](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@Francesco](https://discourse.processing.org/u/Francesco)\
**Post date:** [July 3, 2020, 7:11am UTC](https://discourse.processing.org/t/problema-con-nullpointerexception/22349/1 "2020-07-03T07:11:35Z")

</div>

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”;

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [July 3, 2020, 9:22am UTC](https://discourse.processing.org/t/problema-con-nullpointerexception/22349/2 "2020-07-03T09:22:27Z")

</div>

Hi @Francesco,

Welcome to the community! 🙂

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](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.

---

<div class="post-metadata">

**Author:** ![Francesco](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@Francesco](https://discourse.processing.org/u/Francesco)\
**Post date:** [July 3, 2020, 7:55pm UTC](https://discourse.processing.org/t/problema-con-nullpointerexception/22349/3 "2020-07-03T19:55:19Z")

</div>

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