title: Accessing Images from image folder in JAVA
body: <p>I'm beginner to java GUI. And want to access images from the folder but i'm getting the following error.</p>
  
  <p>My Code</p>
  
  <pre><code>import java.awt.Image;
  
  import javax.swing.ImageIcon;
  
  public class Images {
  
      private static String IMG_FOLDER = "C:/Users/RASHID/workspace/images/";
  
      public static Image ICON = getImage(IMG_FOLDER + "icon.png");
  
  private static Images instance; 
  
      private Images() {}
  
      public static Images getInstance() {
          if(instance==null)
              instance = new Images();
          return instance;
      }
  
      public static Image getImage(String image){
          return getImageIcon(image).getImage();
      }
  
      public static ImageIcon getImageIcon(String image){
          return new ImageIcon(getInstance().getClass().getClassLoader().getResource(image));
      }
  }
  </code></pre>
  
  <p>When i try to run this one in main i get the following Errors. I don't know whats happening here.</p>
  
  <pre><code>Exception in thread "main" java.lang.ExceptionInInitializerError
  Caused by: java.lang.NullPointerException
      at javax.swing.ImageIcon.&lt;init&gt;(Unknown Source)
      at Images.getImageIcon(Images.java:38)
      at Images.getImage(Images.java:34)
      at Images.&lt;clinit&gt;(Images.java:9)
  </code></pre>