【发布时间】:2017-01-18 08:26:48
【问题描述】:
在我的映射器中,ArrayIndexOutofBoundsException 旁边是 String temp = word[5];。
我对此进行了研究,我知道错误来自什么(当输入数据为空或长度小于或大于代码中指定的索引时。我的数据有一些空单元格值)
我尝试使用以下代码捕获数组索引错误,但它仍然给我错误。
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
public class AvgMaxTempMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, DoubleWritable> {
public void map(LongWritable key, Text value, OutputCollector<Text, DoubleWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
if(line != null && !line.isEmpty() && str.matches(".*\\d+.*"));
String [] word = line.split(",");
String month = word[3];
String temp = word[5];
if (temp.length() > 1 && temp.length() < 5){
Double avgtemp = Double.parseDouble(temp);
output.collect(new Text(month), new DoubleWritable(avgtemp));
}
}
}
如果您可以给我任何提示或提示,说明错误是否在此代码中,或者我应该查看其他地方,这将节省很多压力!
【问题讨论】:
标签: java hadoop mapreduce indexoutofboundsexception