0

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!

Guy Stimpson
  • 87
  • 11
  • did you try to debug the code? – ItamarG3 Dec 21 '16 at 17:47
  • Yep - no dice. As far as the IDE is concerned, the program has executed and exited correctly. – Guy Stimpson Dec 21 '16 at 17:57
  • May be yo get an Error instead of an Exception? (e.g. an OutOfMemoryError). Or if the Java runtime crashed you should get a crash dump. – Robert Dec 21 '16 at 18:41
  • As we don't have all your code, we can't reproduce the problem. Most likely there's an exception thrown that you ignore, but we can't tell. Create an MCVE and link the necessary input files to reproduce. – Harald K Dec 22 '16 at 11:45

1 Answers1

0

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.

Mordechai
  • 15,437
  • 2
  • 41
  • 82