图片的路径位置在Eclipse swt中找不到

Path location of the image cannot locate in Eclipse swt

我在导出 java 项目时遇到问题。它找不到我的图像的路径。

这是我的图片所在的位置

String image1 = "image/copy.png";
shell.setImage(new Image(display, image1));

它在我导出之前工作,但是当我导出它并更新我的程序时它给我一个错误。我也尝试使用 InputStream 但它给了我 null.

对于指定的 class、org.eclipse.swt.graphics.Image,您需要使用方法 Image(Device device, InputStream stream) 创建图像并使用 getClass().getResourceAsStream( image1 ) 提供包含文件的 inputStream。您可能需要在路径的开头使用“/”。

使用此方法创建图像效果很好。

new Image(device, getClass().getResourceAsStream(localImagePath));