System.out.println not functioning

lathomas64 picture lathomas64 · Jul 21, 2010 · Viewed 28.7k times · Source

What are some scenarios in which java's System.out.println would fail to produce any output. I have a call to it inside of a method and sometimes when the method is called I get the println and othertimes I don't.

Update: I am also using System.out.flush() after the println.

Update: Thank you for the debugging help. It turned out a blocking call to open a dialog made output appear vastly out of the proper order. I thought the method I was trying to print messages for was being called when the dialog closed but the method itself was what was calling the dialog and so after the closing it was already past the printouts which was where i started looking for the test. If someone has the ability to delete this question as the issue was not what was originally asked it'd be appreciated.

Answer

Jason Day picture Jason Day · Jul 21, 2010

System.out.println on some platforms uses buffered output. Depending on what your code is doing, it is possible that the buffers are not flushed before your program exits. Try putting System.out.flush() after your printlns and see if that helps.

Edit:

sometimes when the method is called I get the println and othertimes I don't

How are you verifying that the method is called but the println produces no output? Is it possible your method is throwing an Exception (which is then swallowed) before it gets to the println?

It would, of course, be very helpful to see some actual code.