gpt4 book ai didi

java - 如何解决 "Exception in thread "Animation Thread"java.lang.NullPointerException"?

转载 作者:行者123 更新时间:2023-11-29 02:57:57 25 4
gpt4 key购买 nike

我目前正在将代码从 Processing 移植到 Netbeans。但是,我遇到了一些困难,因为当我在 Netbeans java 中运行它时,在处理中运行的完全相同的代码给了我一个空指针异常。我遇到的错误是:

Exception in thread "Animation Thread" java.lang.NullPointerException
at gardeningmania.GardeningMania.loadPng(GardeningMania.java:303)
at gardeningmania.GardeningMania.setupThreading(GardeningMania.java:315)
at gardeningmania.GardeningMania.setup(GardeningMania.java:182)
at processing.core.PApplet.handleDraw(PApplet.java:2281)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2177)
at java.lang.Thread.run(Thread.java:722)

这些是导致上述状态错误的部分代码:

@Override

public void setup() {
setupThreading("/Menus/", menuLoader, menuThread);
setupThreading("/Navigations/", navLoader, navThread);
setupThreading("/Navigations2/", nav2Loader, nav2Thread);
}

void loadPng(File[] files, ImageLoader loader) {

for (int i = 0; i < files.length; i++) {
String path = files[i].getAbsolutePath();
if (path.toLowerCase().endsWith(".png")) {
loader.loadImg(path);
}
}
}

void setupThreading(String folderName, ImageLoader loader, Thread threading) {

File dir = new File(sketchPath + folderName);
File[] files = dir.listFiles();
threading = new Thread(loader);
loadPng(files, loader);
threading.start();
}

知道如何解决这些错误吗?

最佳答案

检查您是否指向正确的目录并且它不是相对路径。我觉得下面的代码给出了一个空对象 files:

File[] files = dir.listFiles();

关于java - 如何解决 "Exception in thread "Animation Thread"java.lang.NullPointerException"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21131552/

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