It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Potential problems with getImage() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Potential problems with getImage()" Watch "Potential problems with getImage()" New topic

Potential problems with getImage()

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Hi there,

I get my images using...

But I'm thinking, what happens when the image at the location 'path'
is not there.
Well, I expected the image to be null, but when I tried it:

Which isn't null.

So what happens if I now try to use the image, could I get an exception?
I tried it, and there was no exception, just black where the image should
have been drawn.

Well having black replace the image is fine, but I don't know how I should
handle this situation correctly since it seems no exception is thrown,
so I can't use a try/catch.

Its not that I want it to do anything when there is no image to fetch,
I just don't want it to break if this happens.

Thanks for any input.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
This statement

creates an Image object and loads the image data using a MediaTracker (protected field). To get feedback about the loading process you can use the ImageIcon getImageLoadStatus method. The MediaTracker api comments section has an example that checks for loading status.
I agree. Here's the link:
subject: Potential problems with getImage()
It's not a secret anymore!