Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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字符串[]问题,包含值,但在插入列表时,其行为类似于null<;字符串[]>;_Java_Arrays_String_Csv - Fatal编程技术网

奇数Java字符串[]问题,包含值,但在插入列表时,其行为类似于null<;字符串[]>;

奇数Java字符串[]问题,包含值,但在插入列表时,其行为类似于null<;字符串[]>;,java,arrays,string,csv,Java,Arrays,String,Csv,我对字符串数组有问题,并试图将其添加到列表中。 下面是用于创建问题的代码 程序在循环的第一次运行中失败,我已经使用OpenCSV验证了来自CSV的输入 List<String[]> output = null; String[] temp; for(int i = 0; i < 13; i++) { temp = reader.readNext(); //read next line i

我对字符串数组有问题,并试图将其添加到列表中。 下面是用于创建问题的代码

程序在循环的第一次运行中失败,我已经使用OpenCSV验证了来自CSV的输入

List<String[]> output = null;
String[] temp;

for(int i = 0; i < 13; i++)
{               
    temp = reader.readNext();                           //read next line into temp
    System.out.println(temp[0]+temp[1]+temp[2]);        //temp output
    temp[2] = String.valueOf((values[i])/100);          //assign new value
    System.out.println(temp[0]+temp[1]+temp[2]);        //temp output
    output.add(temp);
}
前两行是正确的,按如下方式分开: 温度[0]温度[1]温度[2] VANC子弹头0.311 VANC BULLET 0.308

问题(如错误读取)出现在:

文件内容如下:

NullPointerException - if the specified element is null and this list does not permit null elements
但正如您从我的输出(第二行)中看到的,数组“temp”不是null,它在每个元素中分别包含“VANC BULLET 0.308”

我被难住了。有没有人有想法或看到我没看到的东西


谢谢

据我所知,您从未初始化过
列表输出=null在您的代码中。因此,当它调用
List.add时,由于List仍然为空,它抛出NPE

首先初始化它:

List<String[]> output = new ArrayList<String[]>();
List output=new ArrayList();

列表
输出
定义为空

List<String[]> output = null;

这不会编译
temp=reader.readNext()但我怀疑您没有给出
temp
值。
List<String[]> output = new ArrayList<String[]>();
List<String[]> output = null;
List<String[]> output = new ArrayList<String[]>();