以下代碼給我一個NullPointerException
。問題是以下行:使用HashMap的put方法時的NullPointerException
...
dataMap.put(nextLine[0], nextLine[6]);
奇怪的是,我已經沒有上述線路和呼叫nextLine[0]
和nextLine[6]
工作完全按預期運行這段代碼 - 這是他們給我回一個元素csv文件。我聲明並初始化HashMap
的代碼早些時候方法
String[] nextLine;
int counter=0;
while (counter<40) {
counter++;
System.out.println(counter);
nextLine = reader.readNext();
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + " - " + nextLine[6] +" - " + "etc...");
dataMap.put(nextLine[0], nextLine[6]);
}
return dataMap;
}
這個問題真的沒有明確地初始化嗎?爲空? – 2009-04-09 16:13:42
我認爲Codingscape的意思是說「沒有實例化」 – 2009-04-09 17:34:52