title: Java - ImageIO throws IllegalArgumentException
body: <p>Hello Java Developers,</p>
  
  <p>So I have recently encountered this problem. Here's and SSCCE:</p>
  
  <pre><code>public class SampleClass extends JPanel{
  
      private Image img;
      private final String IMG_DIRECTORY = ("/res/BG.png");
  
      public SampleClass(){
  
          try{
              img = ImageIO.read(getClass().getResource(IMG_DIRECTORY));
          } catch (IOException ioEx) {
              ioEx.printStackTrace();
          }
      }
  
      @Override
      public void paintComponent(Graphics g){
          super.paintComponent(g);
  
          g.drawImage(img, 0, 0, null);
      }
  
  }
  </code></pre>
  
  <p>This line throws the exception</p>
  
  <pre><code>img = ImageIO.read(getClass().getResource(IMG_DIRECTORY));
  </code></pre>
  
  <p>Here's the StackTrace:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: input == null!
      at javax.imageio.ImageIO.read(Unknown Source)
      at com.forte.project.chatservice.uicomponent.FrameBackground.&lt;init&gt;(FrameBackground.java:27)
      at com.forte.project.chatservice.ui.MainFrame.&lt;init&gt;(MainFrame.java:27)
      at com.forte.project.chatservice.ChatService.main(ChatService.java:18)
  </code></pre>
  
  <p>I have done the following:<br>
  - Google. <br>
  - Updated my Java <br>
  - .getResourceAsStream(IMG_DIRECTORY); <br>
  - this.getClass().getResource(IMG_DIRECTORY)); <br>
  - MainClass.class.getClass().getResource(IMG_DIRECTORY);</p>