这段代码应该从一个文件中读取,并将每个条目解析为它成功从文件读取的点数组中的双精度,但每当它尝试解析输入tp double时,它都会给出空指针异常。
try {
BufferedReader br = new BufferedReader(new FileReader("dataset.csv"));
int j = 0;
while ((line = br.readLine()) != null) {
String [] pointtemp = line.split(split);
//check
point = new double[point.length];
for (int i = 0; i< pointtemp.length; i++){
point[i] = Double.parseDouble(pointtemp[i]);
System.out.println(point[i]);
}
points [j] = new point(point);
j++;
}
答案 0 :(得分:4)
您的double[]
初始化不正确。将其声明为
point = new double[pointtemp.length];
答案 1 :(得分:0)
试着用try&amp; amp;捕获机制并打印(在catch中)pointtemp [i]的值。也许你正试图解析一个空单元格?