Aha! Here we are:
There are
two exceptions here. Why is that? I followed the stack trace for the first exception, starting at your call to ImageIO.write(). I followed it into source code (I lucked out that you seem to be using JDK 6, same as me, so the line numbers were the same. When I got to FileImageOutputStreamSpi.java line 37, I found this:
What happens here is that new FileImageOutputStream() throws a FileNotFoundException, but some Sun programmer went and caught the exception, printed the stack trace, and returned null. Which is why it's no longer possible to catch the FileNotFoundException - it's already printed. Shortly afterwards, the returned null value causes a NullPointerException, which is what it being thrown from the method you called. I also found this
bug report, so Sun is aware of the problem. Note that the bug has been there since JDK 1.4, so don't expect them to fix it anytime soon. Sigh.
You
could catch the NullPointerException, but you'll still get the NileNotFoundException printed confusingly in your log. Probably your best bet here is to check for the existence of the file
before you try to call ImageIO.write(). Or maybe you ahsould just check that the directory, is valid, e.g.