次のコードは私にNullPointerException
. 問題は次の行にあります。
...
dataMap.put(nextLine[0], nextLine[6]);
奇妙なのは、上記の行なしでこのコードを実行し、呼び出しが期待どおりに機能することです。つまり、csv ファイルの要素が返されますnextLine[0]
。コードでnextLine[6]
を宣言して初期化しますHashMap
HashMap<String, String> dataMap = null;
メソッドの早い段階で
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;
}