// filename is a String == "patch.jpg"
final Toolkit toolKit = Toolkit.getDefaultToolkit();
Image tmpImage = toolKit.createImage(filename);
toolKit.prepareImage(tmpImage, -1, -1, this);
and the image wasn't found, I get an error returned to my imageUpdate
method and that's all I hear about it and I can go to plan B (using a
regular background). But if I want to get the image out of a jar file
instead of the current directory, I change that to:
final Toolkit toolKit = Toolkit.getDefaultToolkit();
URL imgURL = getClass().getResource("/"+filename);
Image tmpImage = toolKit.createImage(imgURL);
toolKit.prepareImage(tmpImage, -1, -1, this);
And it works the same if the file is there in the jar file, but if it
isn't, I get the following exception appear on the screen:
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:99)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:108)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:251)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:168)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
And I can't seem to catch the exception anywhere. Is there a way to test
if the imgURL exists?
--
Paul Tomblin <ptom...@xcski.com>, not speaking for anybody
Don't use a big word where a diminutive one will suffice.
Did you try "if (imgURL !=null) { ...}"?
Oh man, do I feel stupid! Of course that works. I was confusing it with
something like File("filename"), where just creating it doesn't tell you
if it actually exists or not.
Sorry to waste everybody's time.
--
Paul Tomblin <ptom...@xcski.com>, not speaking for anybody
A bleeding heart can be hell on the carpeting.