• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception at printf()

 
Andrzej Borucki
Ranch Hand
Posts: 83
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote simple program:

In System.console().printf("something") is error, despite in Eclipse I check "Allocate console" in Common tab in Run/Debug configurations
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrzej Borucki wrote:In System.console().printf("something") is error, despite in Eclipse I check "Allocate console" in Common tab in Run/Debug configurations

It would be useful to know what the error is. Is it, for example, a NullPointerException?

I'm pretty sure that the "console" referred to in the tab you mentioned is Eclipse's console, not a Console object, which has only been around since 1.6. I also understand that some IDE's use a background Thread for it, which is incompatible with System.console().

My suggestion: look at the example code in the java.io.Console docs, and use that; and if it doesn't work in Eclipse, try running your program from the command line instead.

Winston
 
Andrzej Borucki
Ranch Hand
Posts: 83
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I create runnable jar, it printf() OK, but with Eclipse IDE is java.lang.NullPointerException
How to write common code - System.console() for outside Eclipse and Eclispe console for inside IDE?
 
Andrzej Borucki
Ranch Hand
Posts: 83
1
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrzej Borucki wrote:http://illegalargumentexception.blogspot.com/2010/09/java-systemconsole-ides-and-testing.html

Well discovered. That's what we like to see.

Winston
 
Andrzej Borucki
Ranch Hand
Posts: 83
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or simply
System.out - black text in Eclipse console
System.err - red text in Eclipse console
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic