简体   繁体   English

不理解 processing.py 的错误

[英]Not understanding an error with processing.py

So I am using Processing.py except I am using it through IDLE as my project requires python modules as well but I am getting an error that makes no sense to me.所以我正在使用 Processing.py,除了我通过 IDLE 使用它,因为我的项目也需要 python 模块,但我收到一个对我来说毫无意义的错误。 Was wondering if anyone here had any ideas on how I could fix it?想知道这里是否有人对我如何修复它有任何想法?

Here's the error I am getting:这是我得到的错误:

>>> The file "Background.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
>> java.lang.NullPointerException
>>  at processing.core.PGraphics.image(PGraphics.java:3767)
>>  at processing.core.PApplet.image(PApplet.java:12132)
>>  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:186)
>>  at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
>>  at org.python.core.PyObject.__call__(PyObject.java:515)
>>  at org.python.core.PyObject.__call__(PyObject.java:521)
>>  at org.python.core.PyMethod.__call__(PyMethod.java:171)
>>  at org.python.pycode._pyx7.f$0(<string>:1)
>>  at org.python.pycode._pyx7.call_function(<string>)
>>  at org.python.core.PyTableCode.call(PyTableCode.java:167)
>>  at org.python.core.PyCode.call(PyCode.java:18)
>>  at org.python.core.Py.runCode(Py.java:1386)
>>  at org.python.core.Py.exec(Py.java:1430)
>>  at org.python.pycode._pyx5.listen$5(i3_jython.py:28)
>>  at org.python.pycode._pyx5.call_function(i3_jython.py)
>>  at org.python.core.PyTableCode.call(PyTableCode.java:167)
>>  at org.python.core.PyBaseCode.call(PyBaseCode.java:124)
>>  at org.python.core.PyFunction.__call__(PyFunction.java:403)
>>  at org.python.pycode._pyx5.draw$2(i3_jython.py:19)
>>  at org.python.pycode._pyx5.call_function(i3_jython.py)
>>  at org.python.core.PyTableCode.call(PyTableCode.java:167)
>>  at org.python.core.PyBaseCode.call(PyBaseCode.java:124)
>>  at org.python.core.PyFunction.__call__(PyFunction.java:403)
>>  at org.python.core.PyFunction.__call__(PyFunction.java:398)
>>  at jycessing.PAppletJythonDriver.draw(PAppletJythonDriver.java:1059)
>>  at processing.core.PApplet.handleDraw(PApplet.java:2403)
>>  at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1527)
>>  at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)

Attached is my file structure which clearly shows that I do in fact have the image file in the working directory附件是我的文件结构,它清楚地表明我实际上在工作目录中有图像文件

这是我的文件结构:

Hope someone will be able to help希望有人能够提供帮助

Odds are that the working directory is not where the script is actually located.可能是工作目录不是脚本实际所在的位置。 This can be solved by getting the absolute path of "background.png" as follows:这可以通过获取“background.png”的绝对路径来解决,如下所示:

import os
dirname = os.getcwd()
filepath = dirname + '/background.png'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM