Java ArrayIndexOutOfBoundsException错误
当我运行代码时,我从reducer的任务中得到Java ArrayIndexOutOfBoundsException错误,java,hadoop,Java,Hadoop,当我运行代码时,我从reducer的任务中得到ArrayIndexOutOfBoundsException错误 我的代码如下: public void map(ImageHeader key, FloatImage value, Context context) throws IOException, InterruptedException{ if (value != null) { mapcounter++; FloatImage gray=new F
ArrayIndexOutOfBoundsException
错误
我的代码如下:
public void map(ImageHeader key, FloatImage value, Context context) throws IOException, InterruptedException{
if (value != null) {
mapcounter++;
FloatImage gray=new FloatImage(value.getWidth(),value.getHeight(),value.getBands());
int imageWidth = value.getWidth();
int imageHeight = value.getHeight();
for (int x = 0; x < imageWidth-1; x++) {
for (int y = 0; y < imageHeight-1; y++) {
float red =value.getPixel(x, y, 0);
float green =value.getPixel(x, y, 1);
float blue =value.getPixel(x, y, 2);
//average of RGB
float avg = (red + blue + green)/3;
//set R, G & B with avg color
gray.setPixel(x, y, 0, avg);
gray.setPixel(x, y, 1, avg);
gray.setPixel(x, y, 2, avg);
}
}
ImageEncoder encoder = JPEGImageUtil.getInstance();
FSDataOutputStream os = fileSystem.create(outpath);
encoder.encodeImage(gray, key, os);
os.flush();
os.close();
context.write(new BooleanWritable(true), new LongWritable(1));
}
else
context.write(new BooleanWritable(false), new LongWritable(0));
}
public static class MyReducer extends Reducer<BooleanWritable, LongWritable, BooleanWritable, LongWritable> {
public void reduce(BooleanWritable key, Iterable<LongWritable> values, Context context)
throws IOException, InterruptedException
{
System.out.println("REDUCING");
for (LongWritable temp_hash : values)
{
context.write(new BooleanWritable(true), new LongWritable(1));
}//for
}
}
我如何解决这个问题
第二个问题:如何在程序中忽略reduce阶段而不运行reduce阶段?看起来这是Apache hoop中的一个bug。他们声称他们已修复了以下内容 它已作为MAPREDUCE-365的一部分修复
有关该错误的详细信息,请参阅。谢谢Jayamohan。我查过了。成功了。非常感谢:)