# \[SOLVED\] Image() nullPtrException

**URL:** <https://discourse.processing.org/t/solved-image-nullptrexception/7424>\
**Category:** Processing.py\
**Created:** [January 11, 2019, 6:12pm UTC](https://discourse.processing.org/t/solved-image-nullptrexception/7424 "2019-01-11T18:12:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [January 11, 2019, 6:12pm UTC](https://discourse.processing.org/t/solved-image-nullptrexception/7424/1 "2019-01-11T18:12:01Z")

</div>

> processing.app.SketchException: java.lang.NullPointerException  
> at processing.core.PGraphics.image(PGraphics.java:3771)  
> at processing.core.PApplet.image(PApplet.java:12655)  
> at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)  
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
> at java.lang.reflect.Method.invoke(Method.java:498)  
> at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:188)  
> at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:206)  
> at org.python.core.PyObject. **call** (PyObject.java:534)  
> at org.python.core.PyObject. **call** (PyObject.java:540)  
> at org.python.core.PyMethod. **call** (PyMethod.java:171)  
> at org.python.pycode.\_pyx45.draw$2(sketch\_190111a.pyde:9)  
> at org.python.pycode.\_pyx45.call\_function(sketch\_190111a.pyde)  
> at org.python.core.PyTableCode.call(PyTableCode.java:171)  
> at org.python.core.PyBaseCode.call(PyBaseCode.java:125)  
> at org.python.core.PyFunction. **call** (PyFunction.java:403)  
> at org.python.core.PyFunction. **call** (PyFunction.java:398)  
> at jycessing.PAppletJythonDriver.draw(PAppletJythonDriver.java:1348)  
> at processing.core.PApplet.handleDraw(PApplet.java:2429)  
> at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1557)  
> at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)  
> at jycessing.mode.run.SketchRunner.convertPythonSketchError(SketchRunner.java:222)  
> at jycessing.mode.run.SketchRunner.lambda$2(SketchRunner.java:119)  
> at java.lang.Thread.run(Thread.java:748)

```auto
img = loadImage("defect_walk0001.png")

def setup():
    size(500,500)

    
def draw():
    background(0)
    image(img,100,100)

```

i created a ’ data ’ folder and put in ’ defect\_walk0001.png

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 11, 2019, 6:30pm UTC](https://discourse.processing.org/t/solved-image-nullptrexception/7424/2 "2019-01-11T18:30:31Z")

</div>

I think by default it looks in the sketch path, not data path.  
Either move your image up a folder, or use `img = loadImage(dataPath("defect_walk0001.png"))`

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [January 11, 2019, 6:33pm UTC](https://discourse.processing.org/t/solved-image-nullptrexception/7424/3 "2019-01-11T18:33:36Z")

</div>

Yes, it works with the absolute path  
😄

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 11, 2019, 6:53pm UTC](https://discourse.processing.org/t/solved-image-nullptrexception/7424/4 "2019-01-11T18:53:53Z")

</div>

> [@Sky](#):
>
> ```python
> img = loadImage("defect_walk0001.png")
> 
> def setup():
> size(500, 500)
> 
> def draw():
> background(0)
> image(img, 100, 100)
> 
> ```

```python
def setup():
    size(500, 500)
    noLoop()

    global img
    img = loadImage('defect_walk0001.png')

def draw():
    background(0)
    image(img, 100, 100)

```

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [January 11, 2019, 7:30pm UTC](https://discourse.processing.org/t/solved-image-nullptrexception/7424/5 "2019-01-11T19:30:41Z")

</div>

Or, yeah, that. Same problem you(@Sky ) encountered in your another question where you struggled with `width` and `height` turning `null` - `dataPath` and `sketchPath` also only work in `setup()` or later.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 11, 2019, 7:42pm UTC](https://discourse.processing.org/t/solved-image-nullptrexception/7424/6 "2019-01-11T19:42:35Z")

</div>

> [@Architector\_4](#):
>
> **dataPath()** and **sketchPath()** also only work in **setup()** or later.

Actually anything related to _sketchPath_ already works as soon as **settings()**. Same for `args[]`. 🤓

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [January 12, 2019, 6:46pm UTC](https://discourse.processing.org/t/solved-image-nullptrexception/7424/7 "2019-01-12T18:46:51Z")

</div>

There is a method to know if an image was successfully loaded ?  
(I’m getting a null ptr error on the 36th frame, but when I print() the loaded files name, it seems all ok)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 12, 2019, 6:50pm UTC](https://discourse.processing.org/t/solved-image-nullptrexception/7424/8 "2019-01-12T18:50:34Z")

</div>

> [@Sky](#):
>
> There is a method to know if an image was successfully loaded?

Nope. We simply check whether **loadImage()** has returned `None`. 😶
