• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Potential problems with getImage()

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic