Image getWidth and getHeight returning -1 but are not suppose to be
<p>Why does this:</p>

<pre><code>URL url = MinecraftPlatformGame.class.getResource("images/diamondPick.png");
image = Toolkit.getDefaultToolkit().getImage(url); 
int width = image.getWidth(null);
int height = image.getHeight(null);
System.out.println(width);
System.out.println(height);
</code></pre>

<p>Return <code>-1</code> for both the <code>width</code> and the <code>height</code></p>

<p>Edit: My question before I figured out the answer was actually how I was suppose to fix it.
I fixed it by doing the following:</p>

<pre><code>URL url = MinecraftPlatformGame.class.getResource("images/diamondPick.png");
image = Toolkit.getDefaultToolkit().getImage(url); 
MediaTracker mTracker = new MediaTracker(this);
  mTracker.addImage(image,1);
        try {
            mTracker.waitForID(1);
        } catch (InterruptedException ex) {
            Logger.getLogger(MinecraftPlatformGame.class.getName()).log(Level.SEVERE, null, ex);
        }
int width = image.getWidth(null);
int height = image.getHeight(null);
System.out.println(width);
System.out.println(height);

url = MinecraftPlatformGame.class.getResource("images/gui.png");
image1 = Toolkit.getDefaultToolkit().getImage(url);
  mTracker.addImage(image1,2);
        try {
            mTracker.waitForID(2);
        } catch (InterruptedException ex) {
            Logger.getLogger(MinecraftPlatformGame.class.getName()).log(Level.SEVERE, null, ex);
        }
        width = image1.getWidth(null);
height = image1.getHeight(null);
System.out.println(width);
System.out.println(height);
</code></pre>

<p>Problem I have now is this doesn't seem very efficient nor does it seem like I should need so much code just for two images to be imported and given sizes. Is there a better more efficient and easier way to do this?</p>
