简体   繁体   中英

Path location of the image cannot locate in Eclipse swt

I have a problem when exporting my java project. It cannot find the path of my image.

  • File Project
    • src
    • config
    • image
      • copy.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.

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. You probably need "/" at the start of your path.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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