A quick disclaimer: I’m a bit of a newbie, so this issue might be just me not seeing the obvious, but basically when I run
def setup(): size(400,400) def test(): strokeWeight(5) circle(100, 100, 100) test()
in Processing I get the following error:
processing.app.SketchException: java.lang.NullPointerException at processing.core.PApplet.strokeWeight(PApplet.java:14431) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 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:497) at org.python.core.PyObject.__call__(PyObject.java:501) at org.python.core.PyMethod.__call__(PyMethod.java:141) at org.python.pycode._pyx58.test$2(sketch_210426a.pyde:6) at org.python.pycode._pyx58.call_function(sketch_210426a.pyde) at org.python.core.PyTableCode.call(PyTableCode.java:171) at org.python.core.PyBaseCode.call(PyBaseCode.java:139) at org.python.core.PyFunction.__call__(PyFunction.java:413) at org.python.pycode._pyx58.f$0(sketch_210426a.pyde:1) at org.python.pycode._pyx58.call_function(sketch_210426a.pyde) at org.python.core.PyTableCode.call(PyTableCode.java:171) at org.python.core.PyCode.call(PyCode.java:18) at org.python.core.Py.runCode(Py.java:1614) at org.python.core.Py.exec(Py.java:1658) at org.python.pycode._pyx57.f$0(/var/folders/vf/3zy00t252_372n6n1n060tc00000gn/T/sketch_210426a6112183873956099370/sketch_210426a.pyde:96) at org.python.pycode._pyx57.call_function(/var/folders/vf/3zy00t252_372n6n1n060tc00000gn/T/sketch_210426a6112183873956099370/sketch_210426a.pyde) at org.python.core.PyTableCode.call(PyTableCode.java:171) at org.python.core.PyCode.call(PyCode.java:18) at org.python.core.Py.runCode(Py.java:1614) at org.python.core.Py.exec(Py.java:1658) at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276) at jycessing.PAppletJythonDriver.processSketch(Unknown Source) at jycessing.PAppletJythonDriver.findSketchMethods(Unknown Source) at jycessing.Runner.runSketchBlocking(Unknown Source) at jycessing.mode.run.SketchRunner.lambda$startSketch$3(Unknown Source) at java.lang.Thread.run(Thread.java:748) at jycessing.mode.run.SketchRunner.convertPythonSketchError(Unknown Source) at jycessing.mode.run.SketchRunner.lambda$startSketch$3(Unknown Source) at java.lang.Thread.run(Thread.java:748)
Interestingly enough, I am only returned the error when any one of Processing’s built in functions (such as setup()
, draw()
or mouseClicked
) is defined as well, so if I ran:
def why_arent_you_working(): print("please") def test(): strokeWeight(5) circle(100, 100, 100) test() why_arent_you_working()
it would work for some reason.
I’ve tried 10 diffrent threads concerning NullPointerException
but I just can’t seem to find what I did wrong. As I’ve prefaced this post, I am a newbie, so its probably some stupid oversight of mine but it would be great if someone helped me out.
Advertisement
Answer
This might be a result of “mixing active and static modes”. Active mode is when you use setup()
and/or draw()
, and static mode is when you don’t. Basically, if you’re using setup()
, you can’t call any functions outside of an indentation (or a variable definition). The standard way to draw a circle on the screen is like this:
def setup(): size(400,400) def draw(): strokeWeight(5) circle(100, 100, 100)
draw()
is called just like setup()
is: it’s automatically called without you explicitly calling it anywhere.
Keep in mind that draw()
is a loop, so it will run continuously until noLoop()
is called.