The Artima Developer Community
Sponsored Link

Java Answers Forum
Eclipse Version: 3.3.1.1

1 reply on 1 page. Most recent reply: Dec 4, 2007 1:50 AM by Vincent O'Sullivan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Murat Bilal

Posts: 1
Nickname: muratzz
Registered: Dec, 2007

Eclipse Version: 3.3.1.1 Posted: Dec 3, 2007 1:11 PM
Reply to this message Reply
Advertisement
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


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Eclipse Version: 3.3.1.1 Posted: Dec 4, 2007 1:50 AM
Reply to this message Reply
> 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.

Flat View: This topic has 1 reply on 1 page
Topic: Eclipse Version: 3.3.1.1 Previous Topic   Next Topic Topic: help me

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use