You can create a new ImageIcon
with ImageIcon icon = new ImageIcon("an image.png")
, but what happens if "an image.png"
doesn't exist, or some other error occurs? I'm writing a program that loads images like this, and I want to check if there was a problem loading an image, but since no Exception
is thrown, how would you check that? Would if (icon == new ImageIcon())
be the correct statement?
EDIT: I was using ImageIO.read
which does throw an exception and makes checking easy but some of the images I need to load are animated gifs which don't animate if you load them with ImageIO.read