title: How to solve java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0?
body: <p>I've been spending the last hours trying to solve the stack trace below. With major research on here SO and also through Google, I understand the exception can mean several things:</p>
  
  <ul>
  <li><p>the program can't find the requested images with the provided path;</p></li>
  <li><p>the images are being rendered <strong>after</strong> the width and the height are generated, reason why it equals 0...</p></li>
  </ul>
  
  <p>Am I missing something? I can't figure out how to solve this... </p>
  
  <p>Stack</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.IllegalArgumentException: Width
    (-1) and height (-1) cannot be &lt;= 0   at
    java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
      at java.awt.image.BufferedImage.(BufferedImage.java:331)  at
    tp6.Interface.toBufferedImage(Interface.java:157)     at
    tp6.Interface.(Interface.java:36)   at
    tp6.Interface.main(Interface.java:171)</p>
  </blockquote>
  
  <p>tp6.Interface.toBufferedImage(Interface.java:157):</p>
  
  <pre><code>public BufferedImage toBufferedImage(Image image) {
  
          if( image instanceof BufferedImage ) {
  
                  return( (BufferedImage)image );
          } else {
  
                  image = new ImageIcon(image).getImage();
  
                  BufferedImage bufferedImage = new BufferedImage(
                                                        image.getWidth(null),
                                                        image.getHeight(null),
                                                        BufferedImage.TYPE_INT_RGB );
                  Graphics g = bufferedImage.createGraphics();
                  g.drawImage(image,0,0,null);
                  g.dispose();
                  return( bufferedImage );
          }
  }
  </code></pre>
  
  <p>tp6.Interface.(Interface.java:36)</p>
  
  <pre><code>//IMAGE JPANEL
  Image map=new ImageIcon("images/main.gif").getImage();
      Image digi=new ImageIcon("images/digits.gif").getImage();
      BufferedImage mapmodifiable= toBufferedImage(map);
      BufferedImage digits= toBufferedImage(digi);
  </code></pre>
  
  <p>tp6.Interface.main(Interface.java:171)</p>
  
  <pre><code>public static void main(String[] args)
      {
          Window windowintro = new Window( 440, 400, 1);
          //INTERFACE GRAPHIC
          Interface graphic=new Interface();
  
          graphic.addWindowListener(new WindowAdapter() {
                          @Override
              public void windowClosing(WindowEvent evt) {
                  System.exit(0);
              }
          });
      }
  </code></pre>