RCP应用程序中不同元素的路径

时间:2013-02-07 03:59:56

标签: java eclipse exception eclipse-rcp

我正在使用eclipse创建一个RCP应用程序,我无法加载图像,因为我不知道如何在生成的代码中找到它。我将尝试解释我的特定问题。

注意:该项目是一个游戏编辑器,它位于:http://chelder86.github.com/ArcadeTongame/

首先,这是项目结构:

enter image description here

下一个代码在changing the Working Workspace in the Eclipse Running Config.

之后在Eclipse中正确运行RCP应用程序
package figures;

(...)

public class Sound extends ImageFigure {

  public Sound()  { 

      String picturePath = "src/figures/Sound48.png";
      // or String picturePath = "bin/figures/Sound48.png";

      Image image = new Image(null, picturePath);
      this.setImage(image); 
  }
}

但是当我创建产品并将其导出为RCP应用程序时,它不起作用。我的意思是,RCP应用程序可以正常工作,但它不会加载该图像。 注意:build.properties已检查图像。

我尝试了不同的组合,结果相同:java.io.FileNotFoundException,当我在Eclipse中运行它时:

package figures;
(...)

public class Sound extends ImageFigure {

  public Sound()  { 

      String picturePath = getClass().getResource("Sound48.png").getPath();
      // or String picturePath = this.getClass().getClassLoader().getResource("bin/figures/Sound48.png").getPath(); 
      // or String picturePath = this.getClass().getClassLoader().getResource("figures/Sound48.png").getHost(); 
      // or similars

      Image image = new Image(null, picturePath);
      this.setImage(image);
    }
}

我怎样才能正确加载?

感谢您的帮助! :)

卡洛斯

1 个答案:

答案 0 :(得分:0)

尝试在“icons”文件夹旁边创建单独的“数字”文件夹。只放置图像文件,而不是.java文件。不要忘记将它添加到类路径和build.properties中。那么这样的事情应该有效:

InputStream in = getClass().getResourceAsStream("figures/Sound48.png");
Image image = new Image(Display.getDefault(), in);