Java application closes after BufferedImage without throwing exception

172 views Asked by At

I have a weird problem that I can't even determine the logic behind, let alone how to fix. I have a screensaver app which I'm writing on NetBeans on a Mac. I'm now trying to port the code to work on a Windows 10 machine. The app runs, but seems to exit, without throwing an exception, when it reaches the point where an image is buffered. Sometimes it buffers fine and everything's AOK. However, at other times it gets as far as bi = ImageIO.read(imageList[n]); and then NetBeans happily announces that the code has completed and exits as if nothing untoward has happened.

            int done = 0;
            BufferedImage bi = null;
            while (done == 0) {
                System.out.println("Entered loop");
                bi = ImageIO.read(imageList[n]);
                if (bi == null) {
                    System.out.println("Image null");
                } else {
                    System.out.print("I tried to buffer but failed");
                }
                int biw = bi.getWidth();
                System.out.println("Image width = " + biw);
                if (bi != null) {
                    System.out.println("Image buffered");
                    done = 1;
                }
                System.out.println("done=" + done);
            }

The error messages I've tried to set up, namely "I've tried to buffer but failed" is never printed, but "Entered loop" is, so I can be pretty confident the drop-out happens in the aforementioned line.

Any ideas? Many thanks!

1

There are 1 answers

2
Mordechai On

Well, it's impossible to tell, as you violated a strict rule: Never leave the catch block empty.

A standard catch block should print the stack trace:

catch(Exception e)  {
    e.printStackTrace();
}

This should give you enough hints on your issue.