Meaningless Drivel is fun!*
The moose likes IDEs, Version Control and other tools and the fly likes Giving console arguments using Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Giving console arguments using Eclipse" Watch "Giving console arguments using Eclipse" New topic
Author

Giving console arguments using Eclipse

shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
I am learning to use the Eclipse IDE. I am using the console class to get an input. While running the program, I give the console input using the "Arguments\Program Arguments" tab. However I am still getting NPE. Do I need to do anything else? The programs runs fine as a text file.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

System.console() only returns a non-null value if you run the application from an actual command line. IDEs like Eclipse don't have one, they just mimic one. However, that means that System.console() returns null. You can't prevent that. You'll just have to test your application from a good-old command prompt window.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
Hi Rob,

Thanks. I am actually learning to use Eclipse after using Notepad for a long time. What else works with Eclipse if we need to get input from user?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

A Scanner wrapped around System.in should work.
 
wood burning stoves
 
subject: Giving console arguments using Eclipse
 
Similar Threads
Reading Through System.in
eclipse 3.0.2
program to show Objects available for GC(garbage collection).
Eclipse 1.3 and Scanner hasNext()
Program running much slower when run as an executable jar