0

I'm using eclipse to created an RCP Application, and I'm not being able to load an image because I don't know how to find it in the generated code. I'm going to try to explain my particular issue.

Note: the project is a Game editor, and it is located here: http://chelder86.github.com/ArcadeTongame/

Firstly, this is the project structure:

enter image description here

The next code runs the RCP application correctly inside Eclipse, after changing the Working Workspace in the Eclipse Running Config.

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); 
  }
}

But it does not work when I create a Product and export it as an RCP Application. I mean, the RCP application works, but it does not load that image. Note: build.properties has the image checked.

I tried different combinations like these with the same result: java.io.FileNotFoundException, when I run it in 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);
    }
}

How could I load it correctly?

Thanks for any help! :)

Carlos

Community
  • 1
  • 1
chelder
  • 3,819
  • 6
  • 56
  • 90
  • There is a lack of documentation of Eugenia (a graphical DSL designer), so I upload the solution here: http://estiloasertivo.blogspot.com.es/2013/02/eugenia-epsilon-gmf-howto-use-images.html Thanks Alexey! – chelder Feb 12 '13 at 19:09

1 Answers1

0

Try creating a separate "figures" folder alongside "icons" folder. Put only the image files there, not .java files. Don't forget to add it to the class path and to build.properties. Then something like this should work:

InputStream in = getClass().getResourceAsStream("figures/Sound48.png");
Image image = new Image(Display.getDefault(), in);
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487