[SOLVED] Image() nullPtrException

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)

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

1 Like

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"))

1 Like

Yes, it works with the absolute path
:smile:

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

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


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

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.

1 Like

Actually anything related to sketchPath already works as soon as settings(). Same for args[]. :nerd_face:

1 Like

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)

Nope. We simply check whether loadImage() has returned None. :no_mouth: