Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java csv文件中的行数组_Java_Csv - Fatal编程技术网

Java 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

我正在尝试在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
循环检查。

您需要初始化数组,在您的情况下,数组看起来需要是动态的


研究如何使用java

是的,它可以是空的,您看到的是错误的东西。:)

数组后代码行未初始化

退房

干杯