title: Load images in jar file
body: <p>I'm trying to load an image from an executable JAR file.</p>
  
  <p>I've followed the information from <a href="https://stackoverflow.com/questions/8960381/runnable-jars-missing-images-files-resources">here</a>, then the information from <a href="https://stackoverflow.com/questions/10489773/getting-images-from-a-jar-file">here</a>.</p>
  
  <p>This is the function to retrieve the images:</p>
  
  <pre><code>public static ImageIcon loadImage(String fileName, Object o) {
       BufferedImage buff = null;
       try {
          buff = ImageIO.read(o.getClass().getResource(fileName));
          // Also tried getResourceAsStream
      } catch (IOException e) {
          e.printStackTrace();
          return null;
      }
      if (buff == null) {
          System.out.println("Image Null");
          return null;
      }
      return new ImageIcon(buff);
  }
  </code></pre>
  
  <p>And this is how it's being called:</p>
  
  <pre><code>logo = FileConverter.loadImage("/pictures/Logo1.png", this);
  JFrame.setIconImage(logo.getImage());
  </code></pre>
  
  <p>With <em>this</em> being a simple Object.
  I'm also not getting a <em>NullPointerException</em> unless it is being masked by the UI.</p>
  
  <p>I checked the JAR file and the image is at:</p>
  
  <blockquote>
    <p>/pictures/Logo1.png</p>
  </blockquote>
  
  <p>This current code works both in eclipse and when it's been exported to a JAR and run in a terminal, but doesn't work when the JAR is double clicked, in which case the icon is the default JFrame icon.</p>
  
  <p>Thanks for you're help. It's probably only me missing something obvious.</p>