# NullPointerExeption with loading images

**URL:** <https://discourse.processing.org/t/nullpointerexeption-with-loading-images/360>\
**Category:** Coding Questions\
**Created:** [May 25, 2018, 3:01am UTC](https://discourse.processing.org/t/nullpointerexeption-with-loading-images/360 "2018-05-25T03:01:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![squatting\_potato](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@squatting\_potato](https://discourse.processing.org/u/squatting_potato)\
**Post date:** [May 25, 2018, 3:01am UTC](https://discourse.processing.org/t/nullpointerexeption-with-loading-images/360/1 "2018-05-25T03:01:53Z")

</div>

Hi, i need to load 4 images and draw them in a window, but i get this error.

here’s my code

```auto
PImage image;
PImage image1;
PImage image2;
PImage image3;
String path ="";
void setup() {
  size(360, 240);
  text("click window to load an image", 100, 120);
}

void handleImage(File selection) {
  if (selection==null) {
    println ("Error: 404");
  } 
  else {
    path = selection.getAbsolutePath();
    image = loadImage(path);
    image1 = loadImage(path);
    image2 = loadImage(path);
    image3 = loadImage(path);
    surface.setSize(image.width * 2, image.height * 2);
  }
}
 
void mouseClicked() {
  image = null;
  selectInput("select an image", "handleImage");
}

void draw() {
  if (image != null) {
    image(image, 0, 0 );
    image(image1, image.width, 0 );
    image(image2, 0, image.height);
    image(image3, image.width, image.height);
    //image.filter(GRAY);
    //treshold(image1, 1, image.width, 0 );
    //ditherio(image2, 1, 0, image.height);
    //ditherio(image3, 4, image.width, image.height);
  }
}

```

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [May 25, 2018, 6:26am UTC](https://discourse.processing.org/t/nullpointerexeption-with-loading-images/360/2 "2018-05-25T06:26:18Z")

</div>

Which line is highlighted when it gives the error?

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [May 25, 2018, 6:07pm UTC](https://discourse.processing.org/t/nullpointerexeption-with-loading-images/360/3 "2018-05-25T18:07:40Z")

</div>

> [@squatting\_potato](#):
>
> if (image != null)

Change this to **if (image3 != null)**. Notice you are calling loadImage four times to load the same resource. Instead, you could do: `image3=image.get()` as this is faster. The mean reason of your error is that you check for null content on only one object and you assume the other ones “should” be ok.

Kf
