1

我想使用TwoDArrayWritableas value 发出一个二维双精度数组。

如何写context.write(key , )

编辑

以及Reducer如何将get它们放入二维双精度数组和print值中。

WroteMapper

row = E.length;
col = E[0].length;
                     TwoDArrayWritable array = new TwoDArrayWritable (DoubleWritable.class);
                     DoubleWritable[][] myInnerArray = new DoubleWritable[row][col];
                     // set values in myInnerArray
                     for (int k1 = 0; k1 < row; k1++) {
                        for(int j1=0;j1< col;j1++){
                            myInnerArray[k1][j1] = new DoubleWritable(E[k1][j1]);

                    }
                 array.set(myInnerArray);
                 context.write(clusterNumber, array);

但显示一个Nullpointer exception

13/11/01 16:34:07 INFO mapred.LocalJobRunner: Map task executor complete.
13/11/01 16:34:07 WARN mapred.LocalJobRunner: job_local724758890_0001
java.lang.Exception: java.lang.NullPointerException
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:404)
Caused by: java.lang.NullPointerException
    at org.apache.hadoop.io.TwoDArrayWritable.write(TwoDArrayWritable.java:91)
    at org.apache.hadoop.io.serializer.WritableSerialization$WritableSerializer.serialize(WritableSerialization.java:100)
    at org.apache.hadoop.io.serializer.WritableSerialization$WritableSerializer.serialize(WritableSerialization.java:84)
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:945)
    at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:601)
    at org.apache.hadoop.mapreduce.task.TaskInputOutputContextImpl.write(TaskInputOutputContextImpl.java:85)
    at org.apache.hadoop.mapreduce.lib.map.WrappedMapper$Context.write(WrappedMapper.java:106)
    at edu.Mapper.map(Mapper.java:277)


Mapper.java:277 : context.write(clusterNumber, array);
4

2 回答 2

1
 TwoDArrayWritable array = new TwoDArrayWritable (DoubleWritable.class);
 DoubleWritable[][] myInnerArray = new DoubleWritable[10][];
 // set values in myInnerArray
 array.set(myInnerArray);
 context.write(key, array);

我相信 NPE 是因为数组的某些元素为空。从您发布的代码中,我想知道是否ecol相等col

于 2013-11-01T10:17:51.227 回答
0

伙计们,这个 NPE 异常发生在您的数组中的某个空值上。如果数组中没有任何值,那么它会将空露水放在自然界中的对象上。您可以在调试模式下进行检查。所以你的任务是检查你的数组中没有空值。

于 2016-03-26T18:08:21.127 回答