• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting NPE while using Console

 
Rohan Kayan
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to run following code from Eclipse



Every time I am getting NullPointerException , what could be the issue ??
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot get a Console from eclipse. You can try out the examples from this article on your command line -> http://www.certpal.com/scjp-6-Console.html
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because in some jvm there may not be a console.
from K&B:
Keep in mind that it's possible for your Java program to be running in an environment that doesn't have access to a console object, so be sure that your invocation of System.console() actually returns a valid console reference and not null.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because in some jvm there may not be a console.


To correct that a little, some JVM environments may not have a console
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic