• Post Reply Bookmark Topic Watch Topic
  • New Topic

System.console() Problem  RSS feed

 
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


K&B book
pg-458







compiler is not asking for any input at run time
please tell how to complie and run it
 
Sheriff
Posts: 9611
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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??
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using Jcreator

The following Exception occurs

Exception in thread "main" java.lang.NullPointerException
at NewConsole.main(NewConsole.java:6)
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ;) ?
 
Ranch Hand
Posts: 74
Linux Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!