0

I am working on a project and i am trying to set the icon for the frame. I debug it in eclipse and it works fine without a problem but when I go to export it, it does not find the image when i run the jar file.

Here is my try/catch

try {
frame.setIconImage(ImageIO.read(new File("res/Icon.png")));
} catch (IOException e) {
e.printStackTrace();
}

Here is my file structure.

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
  • `new File("res/Icon.png")` reads a **file**, on the **file system**, in `/res/Icon.png`. Use ClassLoader.getResourceAsStream(). There are dozens of question about that. – JB Nizet Jun 17 '15 at 17:01
  • That didn't fix it, it stopped it from working in eclipse. – Bradley Frost Jun 17 '15 at 18:28
  • Because res is not marked as a source directory. Or because you screwed up. Put the images with your source files, under a package. If they're in package foo.bar, then load them using ClassLoader.getResourceAsStream("foo/bar/image.png"). – JB Nizet Jun 17 '15 at 19:24

0 Answers0