gpt4 book ai didi

python - saveFrame 产生 NullPointerException 错误

转载 作者:行者123 更新时间:2023-12-01 07:30:19 25 4
gpt4 key购买 nike

我对处理还是新手,并且正在使用 Python,但编译器似乎会产生 NullPointerException 错误。如何解决这个问题?

如果有帮助,我正在使用 Windows。

这是原始程序代码-

def setup():
size(400, 400)
stroke(255)

def draw():
line(150, 25, mouseX, mouseY)

def mousePressed():
background(192, 64, 0)

saveFrame("output.png")

processing.app.SketchException: java.lang.NullPointerException
at processing.core.PApplet.saveFrame(PApplet.java:3984)
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._pyx387.f$0(sketch_190727c.pyde:1)
at org.python.pycode._pyx387.call_function(sketch_190727c.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._pyx386.f$0(C:/Users/Abi/AppData/Local/Temp/sketch_190727c1462189324264258430/sketch_190727c.pyde:96)
at org.python.pycode._pyx386.call_function(C:/Users/Abi/AppData/Local/Temp/sketch_190727c1462189324264258430/sketch_190727c.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(PAppletJythonDriver.java:230)
at jycessing.PAppletJythonDriver.findSketchMethods(PAppletJythonDriver.java:590)
at jycessing.Runner.runSketchBlocking(Runner.java:398)
at jycessing.mode.run.SketchRunner.lambda$2(SketchRunner.java:112)
at java.lang.Thread.run(Thread.java:748)

at jycessing.mode.run.SketchRunner.convertPythonSketchError(SketchRunner.java:224)
at jycessing.mode.run.SketchRunner.lambda$2(SketchRunner.java:119)
at java.lang.Thread.run(Thread.java:748)
```

最佳答案

考虑一下 saveFrame() 函数何时被调用。

您已将对 saveFrame() 的调用置于与 setup()draw() 声明相同的级别和 mousePressed() 函数。这意味着您在调用其他函数之前调用saveFrame()。这就是导致 NullPointerException 的原因。

要解决此问题,您可能需要移动 saveFrame() 调用,使其位于 mousePressed() 函数内。

顺便说一句,这是一个运行时错误,而不是编译器错误。

关于python - saveFrame 产生 NullPointerException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57234904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com