试图运行代码
// Create a label with an image
Image image = new Image(display, "interspatial.gif");
Label imageLabel = new Label(shell, SWT.NONE);
imageLabel.setImage(image);
给我错误信息
Exception in thread "main" org.eclipse.swt.SWTException:
i/o error (java.io.FileNotFoundException: interspatial.gif
(O sistema não pode encontrar o arquivo especificado))
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.graphics.ImageLoader.load(Unknown Source)
at org.eclipse.swt.graphics.ImageDataLoader.load(Unknown Source)
at org.eclipse.swt.graphics.ImageData.<init>(Unknown Source)
at org.eclipse.swt.graphics.Image.<init>(Unknown Source)
at examples.ch5.LabelExample.main(LabelExample.java:31)
Caused by: java.io.FileNotFoundException:
interspatial.gif
(O sistema não pode encontrar o arquivo especificado)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at org.eclipse.swt.internal.Compatibility.newFileInputStream(Unknown Source)
... 5 more
附加信息:
在 Eclipse 中,我展开 Chapter05,然后是 examples.ch5,然后右键单击 LabelExample.java,然后选择 Run As,然后选择 1 Java Application。
我尝试将 interspatial.gif 放在 Chapter05 目录、示例目录、ch5 目录和图像目录(可能与同一章的其他源代码有关)。
有“一个包examples.ch5;” 文件开头的行。
为什么图片加载不出来?