简体   繁体   English

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

[英]Path location of the image cannot locate in Eclipse swt

I have a problem when exporting my java project.导出我的 java 项目时遇到问题。 It cannot find the path of my image.它找不到我的图像的路径。

  • File Project档案项目
    • src源文件
    • config配置
    • image图片
      • copy.png复制.png

This is where my image is located这是我的图像所在的位置

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

It works before i export but when i export it and update my program it gives me an error.它在我导出之前工作,但是当我导出它并更新我的程序时,它给了我一个错误。 I tried also to use InputStream but it gives me null.我也尝试使用InputStream但它给了我空值。

With the specified class, org.eclipse.swt.graphics.Image, you will want to create the Image with method Image(Device device, InputStream stream) and use getClass().getResourceAsStream( image1 ) to supply the inputStream containing the file.使用指定的类 org.eclipse.swt.graphics.Image,您需要使用 Image(Device device, InputStream stream) 方法创建 Image,并使用 getClass().getResourceAsStream( image1 ) 提供包含该文件的 inputStream。 You probably need "/" at the start of your path.您可能需要在路径开头使用“/”。

用这种方法创建图像效果很好。

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

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

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