import java.io.*;
public class listjava
{
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;
}
}
我得到了這樣的錯誤:在我的Java程序中導致NullPointerException的原因是什麼?
Exception in thread "main" java.lang.NullPointerException
at listjava.main(listjava.java:7)
爲什麼我的程序錯了嗎?
謝謝,你說得對。還有一個問題?爲什麼在使用IDE時出現這種錯誤?謝謝! – 2011-01-30 03:21:18