当前位置: 代码迷 >> J2SE >> JAVA中Console中readerlin()的有关问题,求帮助
  详细解决方案

JAVA中Console中readerlin()的有关问题,求帮助

热度:85   发布时间:2016-04-23 20:00:37.0
JAVA中Console中readerlin()的问题,求帮助!
	
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
scan.nextLine();
String name = null;
Console cons = null;
cons = System.console();
if (cons != null) {
name = cons.readLine("Name:");
}
System.out.println(name);
}

控制台报错,抛出空指针,论坛中的方法也试过,没找到解决办法。
该怎么去做呢?Scanner的就不用了,我正在研究这个Console的问题,所以Scanner解决办法不用。
求解答!谢谢拉!
------解决思路----------------------
把system.out.放if中就不报空指针了
  相关解决方案