This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
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.
subject: Potential problems with getImage()
It's not a secret anymore!