1

I have researched this topic on the site, and tried the solutions but nothing that has worked for me so far. I have created a simple program in IntelliJ that compiles just fine, but when I export and make it into a JAR there are errors because of the images. When I take away the images I am able to build and load the JAR file correctly. I keep my image in the SRC file in a sub folder named sample.

public class Main extends Application {

    Image image = new Image(String.valueOf(getClass().getResource("/buttona.png")));

    Button button1 = new Button("", new ImageView(image));
    Button button2 = new Button();
Towfik Alrazihi
  • 536
  • 3
  • 8
  • 25
  • 1
    Possible duplicate of [How to add resource file to JAR in IntelliJ](http://stackoverflow.com/questions/29887524/how-to-add-resource-file-to-jar-in-intellij) – fabian Sep 01 '16 at 19:51

1 Answers1

1

I figured it out and wanted to post the solution for future users. It worked when I used the format shown at the bottom. The key was putting GetClassLoader, and from then finding a path that would work.

np0_up.png is the file

Image Num0 = new Image( getClass().getClassLoader().getResourceAsStream( "sample/np0_up.png"));