Hi My code is: import java.io.Console;; public class OkuYaz {
public static void main(String[] args) {
Console konsol=System.console(); konsol.printf("Adiniz:"); String ad=konsol.readLine(); konsol.printf("Yasiniz:"); int yas=Integer.parseInt(konsol.readLine()); konsol.printf("Hosgeldin! %s %nYasin: %d %n",ad,yas); } } but when i run it it gives me this error: Exception in thread "main" java.lang.NullPointerException at OkuYaz.main(OkuYaz.java:10) java:10 line is -->konsol.printf("Adiniz:"); I do not know why,but everything is ok when i try to run it from command line.I use OpenSuse 10.2 and java version 1.6.0_03.Is that something wrong with my IDE Eclipse version 3.3.1.1
> I do not know why,but everything is ok when i try to run > it from command line.I use OpenSuse 10.2 and java version > 1.6.0_03.Is that something wrong with my IDE Eclipse > version 3.3.1.1
As you can see from the following extract from the Javadoc for java.io.Console...
"If this virtual machine has a console then it is represented by a unique instance of this class which can be obtained by invoking the System.console() method. If no console device is available then an invocation of that method will return null."
...invoking System.console can return null.
That is what happens when you run the code from within eclipse. You're code doesn't allow for that; therefore it crashes.
A Google search show that it is a known eclipse issue. The simplest solution is to always run the code from the command line though there may be work-arounds that allow the code to work from within eclipse.