本帖最后由 杨震 于 2012-8-11 21:47 编辑
- <p>
- package com.taobao.szyangzhen;
- import java.io.Console;</p><p>public class InputTest {</p><p> /**
- * @param args
- */
- public static void main(String[] args) throws NullPointerException {
-
- Console con = System.console();
-
- System.out.println("what is your name?");
- String name = con.readLine();
-
- System.out.println("what is your age?");
- String passwd = new String(con.readPassword());
-
- System.out.println("name:" + name + "-----" + "passwd:" + passwd);
-
- }
- 为什么总是报错啊,下面是输出(14行是这行代码: String name = con.readLine();)
- what is your name?
- Exception in thread "main" java.lang.NullPointerException
- at com.taobao.szyangzhen.InputTest.main(InputTest.java:14)
- </p><p>}</p>
复制代码 |
|