0

Everything has been working fine in my level editor program I've been working on until I decided to export the JAR file for a beta version. All the image loading works perfectly in Eclipse but once I try to run it as an external JAR file I get this error: http://puu.sh/kP681/1be9b77e21.png

Here is the code I'm using to load the image, it is working in Eclipse.

public static void main(String[] args) {
    BufferedImage appIcon = null;
    try {
        appIcon = ImageIO.read(new File("res" + File.separator + "appicon.png"));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    JFrame frame = new JFrame("Mario Map Creator");
    frame.setSize(RESELOUTION);
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    frame.setIconImage(appIcon);

That doesn't appear to be working, that is the MapCreator class.

Then the MapCreatorPanel class

public MapCreatorPanel() {
    this.setLayout(null);
    try {
        levelIcon = new ImageIcon(ImageIO.read(new File("res" + File.separator + "levelicon.png")));
        flagIcon = new ImageIcon(ImageIO.read(new File("res" + File.separator + "flagicon.png")));
        scriptIcon = new ImageIcon(ImageIO.read(new File("res" + File.separator + "scripticon.png")));
    } catch (IOException e) {
        e.printStackTrace();
    }
    scriptManager = new ScriptManager();
}

Thanks for your help in advance!

ALSO NOTE: I've looked at a bunch of other posts on this site and all their solutions didn't seem to work for me (unless I was doing something wrong).

Astram
  • 1
  • 1
  • Use [this](https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResource-java.lang.String-) method. There are plenty of questions here about it to [help you with this](http://stackoverflow.com/questions/25635636/eclipse-exported-runnable-jar-not-showing-images). – user1803551 Oct 18 '15 at 21:30
  • I've tried this before but it gives me an error in Eclipse [here](http://hastebin.com/dafudonali.avrasm) – Astram Oct 18 '15 at 21:33
  • What value does the method I linked to return? – user1803551 Oct 18 '15 at 21:40
  • Actually I didn't notice the second link you gave me at first, then I tried it and Example 2 solved the problem. Thanks man! – Astram Oct 18 '15 at 21:47
  • Give the guy an upvote then. :) – user1803551 Oct 18 '15 at 21:48

0 Answers0