title: Java swing Image always has height and width of -1
body: <p>I know that the method returns -1 when it couldn't get the width or height of the image, but I hope you can tell me why it can't manage to do that. Here I create a few ImageIcons and save them in an Image Array:</p>
  
  <pre><code>for(int x = 0; x &lt; playerSprites.length; x++){
      playerSprites [x] = new ImageIcon("player" + x + ".png").getImage()
  }
  </code></pre>
  
  <p>Later I create an instance of the class which only creates this Array at the moment. When I then want to get the images from the Array in the other class I check their height and width and I always get -1 on both:</p>
  
  <pre><code>public Image nextImage(String name){
      Image image = null;
      if(name.equals("player")){
          if(counter == animationImageManager.getPlayerSprites().length-1){
              counter = 0;
          }
          image = animationImageManager.getPlayerSprites()[counter];
          counter++;
      }
      return image;
  }
  </code></pre>