#测试Console类出错
今天测试Console类的输入功能的时候报错了
import java.io.Console;
import java.util.*;
public class MyTestScanner {
public static void main(String[] args) {
Connsole in=System.console();
String username=in.readLine("User name: ");
char[] passwd=in.readPassword("Password: ");
System.out.println(username);
System.out.println(passwd);
}
}
报错如下
Exception in thread "main" java.lang.NullPointerException
at MyTestScanner.main(MyTestScanner.java:11)
后来了解到这是因为Connsole只能在原生控制台输入,idea或者eclipse的不行,我就尝试在控制台上运行就成功了