Java csv文件中的行数组
我正在尝试在csv文件中创建一个行数组 示例csv:Java csv文件中的行数组,java,csv,Java,Csv,我正在尝试在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 BufferedRead
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
循环检查。您需要初始化数组,在您的情况下,数组看起来需要是动态的
研究如何使用java 是的,它可以是空的,您看到的是错误的东西。:) 数组后代码行未初始化 退房 干杯