以下代码给我一个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