File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes System.console() Problem 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "System.console() Problem" Watch "System.console() Problem" New topic
Author

System.console() Problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634


K&B book
pg-458







compiler is not asking for any input at run time
please tell how to complie and run it


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

mohitkumar gupta wrote:compiler is not asking for any input at run time
please tell how to complie and run it

compiler at runtime, this is new
Anyway, I compiled your program and it doesn't compiler as name is not declared anywhere. After fixing it, I compiled and run your program and there was no problem. The program asked me for password and then infinite series of inputs. Did you use any IDE to run this program??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

i am using Jcreator

The following Exception occurs

Exception in thread "main" java.lang.NullPointerException
at NewConsole.main(NewConsole.java:6)
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
I know Eclipse, and other IDEs do not yet support System.console. This is well documented on the wild wild web. I suspect Jcreator doesn't support it either.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

You will have to perform a null check when you get a console. Not all JVM instances are attached to a console.

compiler at runtime, this is new


JIT compiler ;) ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Mahmoud Hossam
Ranch Hand

Joined: Feb 20, 2010
Posts: 74

There's a problem with that code,though


the variable "name",which is supposed to be a string is not defined

I compiled the code manually using javac,and the compiler complained about "name" not being defined in the code

an error in the book maybe?
Rami Othmane
Greenhorn

Joined: Jul 20, 2011
Posts: 1
Today I had same issue. Go to Java Control Panel . Go to Advanced tab. Go To Java console . Select Show console . Apply then Ok. Try to run your run the program using command line. The code will run fine.

Regards,
Rami Othmane
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: System.console() Problem
 
Similar Threads
K&B book Console example Scjp6
Program for Console
NullPointerException when using java.io.Console
Console class NullPointerException problem
K&B book Console example Scjp6