我正在使用 Hadoop MapReduce 计算每年的最小值和最大值,但是当我运行该程序时,出现错误:FAILED Error: java.lang.ArrayIndexOutOfBoundsException: 5
我认为这是因为我的数据中有空值,因为当没有空值时程序运行正常。
因此,在我的 map 函数中,我写了 if 语句来检查是否有 header 以及是否有 null 值:
public static class ExposureMapper
extends Mapper<Object, Text, Text, MinMaxExposure> {
private Text year = new Text();
private double minexposure;
private Double maxexposure;
private MinMaxExposure outPut = new MinMaxExposure();
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
try {
//Some condition satisfying it is header
if (value.toString().contains("Product")) {
return;
} else if(value.toString()==null) {
return;
}
else{
}
} catch (Exception e) {
e.printStackTrace();
}
String[] solarFields = value.toString().split(",");
year.set(solarFields[2]);
minexposure = Double.parseDouble(solarFields[5]);
maxexposure = Double.parseDouble(solarFields[5]);
try {
outPut.setMinExposure(minexposure);
outPut.setMaxExposure(maxexposure);
context.write(year, outPut);
} catch (IOException e) {
e.printStackTrace();
}
}
但是同样的错误发生了......是不是因为value.toString()==null检查空值的方法不正确?