Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Console class NullPointerException problem  RSS feed

 
Ian Su
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When I compile and run the above code in cmd prompt.It is ok and run successfully.

But when I run on eclipse ide,it shows the NullPointerException at



I hope somebody help me out!
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately when you run a program under Eclipse, the System.console() method returns null. You can either run from a command line, or find a different way of interacting with the user.
 
Ian Su
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:Unfortunately when you run a program under Eclipse, the System.console() method returns null. You can either run from a command line, or find a different way of interacting with the user.


Yes,It is null return.And is there any way to get the console object?Because there is no constructor visible for Console class.Thank you very much Mr Greg.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only if you really run the application from the command line. Anything else, including all IDEs, will cause System.console() to return null.
 
Ian Su
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Only if you really run the application from the command line. Anything else, including all IDEs, will cause System.console() to return null.


Thank you Mr Spoor!I will find the other way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!