csvファイルに行の配列を作成しようとしています。
csvの例:
12,13,14,15
13,14,15,16
11,12,13,14
ここで、配列に3つの文字列を含める必要があります。
私はこれを得た:
public static String[] postcodeRows;
public static void main(String[] arg) throws Exception
{
//read the csv file
BufferedReader CSVFile = new BufferedReader(new FileReader(
"C:\\Users\\randy\\Documents\\postcode csv\\exports\\all-groups.csv"));
//count where we are in the csv file
int csvLine = 0;
postcodeRows[0] = CSVFile.readLine(); // Insert the first line.
// The while checks to see if the data is null. If it is, we've hit the end of the file. If not, process the data
while (postcodeRows[csvLine] != null)
{
csvLine++;
postcodeRows[csvLine] = CSVFile.readLine();
}
// Close the file once all data has been read.
CSVFile.close();
}
今私はこれを手に入れます:
Exception in thread "main" java.lang.NullPointerException
at postcodeCheckup.postcodePanel.main(postcodePanel.java:43)
なぜあり、NullPointerException
どうすればこれを防ぐことができますか?変数を作成することはできません。ループnull
によってチェックされます。while