# Getting a NullPointerException when trying to simply display an image in draw()

**URL:** <https://discourse.processing.org/t/getting-a-nullpointerexception-when-trying-to-simply-display-an-image-in-draw/38015>\
**Category:** Coding Questions\
**Created:** [July 18, 2022, 7:53am UTC](https://discourse.processing.org/t/getting-a-nullpointerexception-when-trying-to-simply-display-an-image-in-draw/38015 "2022-07-18T07:53:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amundsen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/amundsen/32/2497_2.png) [@amundsen](https://discourse.processing.org/u/amundsen)\
**Post date:** [July 18, 2022, 7:53am UTC](https://discourse.processing.org/t/getting-a-nullpointerexception-when-trying-to-simply-display-an-image-in-draw/38015/1 "2022-07-18T07:53:56Z")

</div>

Hello,

I have this issue with Processing 4.0b6/Windows.

This ultrasimple sketch triggers a NullPointerException when trying to display the image within draw(). Otherwise when displaying it within setup() it works fine. Also, the same image has been used in numerous other sketches. The sketch name doesn’t contain any special character.

What’s wrong??? 🤔

```auto
PImage originImg;

void setup() {
  size(800, 600);
  noStroke();
  frameRate(60);
  PImage originImg = loadImage("flood_red_blue_1920x1080_bordure.png");
  //image(originImg, 0, 0, width, height); // works flawlessly if executed here
}

void draw() {
  image(originImg, 0, 0, width, height); // NullPointerException if executed here
}

```

---

<div class="post-metadata">

**Author:** ![amundsen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/amundsen/32/2497_2.png) [@amundsen](https://discourse.processing.org/u/amundsen)\
**Post date:** [July 18, 2022, 8:22am UTC](https://discourse.processing.org/t/getting-a-nullpointerexception-when-trying-to-simply-display-an-image-in-draw/38015/2 "2022-07-18T08:22:05Z")

</div>

Got it! It’s because I wrote `PImage` again on the line with `loadImage`!

---

<div class="post-metadata">

**Author:** ![Quertz](https://avatars.discourse-cdn.com/v4/letter/q/cc9497/32.png) [@Quertz](https://discourse.processing.org/u/Quertz)\
**Post date:** [July 22, 2022, 5:15pm UTC](https://discourse.processing.org/t/getting-a-nullpointerexception-when-trying-to-simply-display-an-image-in-draw/38015/3 "2022-07-22T17:15:18Z")

</div>

Yes Sir. There you create a local variable that shadows the global variable.
