File not found using surface.setIcon(icon) in public class test extends PApplet

cola
Sun, 19 Jan 2025 07:57:15 +0000
Coding Questions

hello,everyone. I can’t find the file when using surface.setIcon(icon) in public class test extends PApplet. I am using the processing4 version. My pictures are saved in data. The file structure is as follows:
MySketch/
test.pde
data/
logo.png
I tried to use the following code to verify whether my image can be called.

PImage img;

public void setup() {
  size(400, 400);
  img = loadImage("logo.png");  // 假设 logo.png 在 data 文件夹中
  if (img != null) {
    image(img, 100, 100);
  } else {
    println("图片加载失败！");
  }
}

This was successful.
When I use the following code, the problem of The file “logo.png” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable appears.

// OpenBioView.java
import processing.core.PApplet;

public class test extends PApplet {
  PImage img;

  public void setup() {
    size(400, 400);
    img = loadImage("logo.png");  // 加载图片
    if (img != null) {
      image(img, 100, 100);  // 显示图片
    } else {
      println("图片加载失败！");
    }
  }

  public void draw() {
    // 绘制图像等内容
  }

  public static void main(String[] args) {
    PApplet.main("test");
  }
}

Does anyone know why this is? I hope someone can help me, thank you very much！

8 posts - 4 participants