Console class in java Exception in reading password

Posted by satheesh on Stack Overflow See other posts from Stack Overflow or by satheesh
Published on 2011-03-11T16:07:14Z Indexed on 2011/03/11 16:10 UTC
Read the original article Hit count: 245

Filed under:

Hi, i am trying to use Console class in java. with this code

import java.io.Console;
public class ConsoleClass {
public static void main(String[] args){
    Console c=System.console();
    char[] pw;
    pw=c.readPassword("%s","pw :");
    for(char ch:pw){
        c.format("%c",ch);
    }
    c.format("\n");
    MyUtility mu =new MyUtility();
    while(true){
        String name=c.readLine("%s", "input?: ");
        c.format("output: %s \n",mu.doStuff(name));

    }

  } 
}
class MyUtility{
String doStuff(String arg1){
    return "result is " +arg1;
}
}

here i am getting NullPointerException when i tried to run in netbeans but i am not getting any Exception when tried to run in cmd with out netbeans IDE.Why?

© Stack Overflow or respective owner

Related posts about java