Hadoop-未加载IntWritable(int)构造函数



我正在尝试在Hadoop中制作MapReduce,并希望将String转换为IntWritable。我遵循以下建议:如何在Hadoop中将String对象转换为IntWritable对象。它建议使用

new IntWriteable(Integer.parseInt(someString))

所以我尝试的是

public class MyMapper extends Mapper<LongWritable, Text, Text, IntWritable > {
private final Text wordKey = new Text("");
public void map(LongWritable ikey, Text value, Context context) throws IOException, InterruptedException {
    String[] friend = value.toString().split(";");
    String[] friendswith = friend[1].split(",");
    for (String s : friendswith) {
        wordKey.set(friend[0]);
        context.write(wordKey, IntWritable(Integer.parseInt(s))); //trying to convert here
      }
   }
}

但是得到错误

The method IntWritable(int) is undefined for the type MyMapper

根据这里的文档,它注意到,有一个构造函数接受int作为输入。我确实导入了IntWritable

import org.apache.hadoop.io.IntWritable;

是什么原因导致我无法使用IntWritable(int)构造函数?

您缺少new关键字。

在线

context.write(wordKey, IntWritable(Integer.parseInt(s)));

您不是在创建IntWritable的实例,而是在尝试调用一个未定义的名为IntWritable的方法。

试试这个:

context.write(wordKey, new IntWritable(Integer.parseInt(s)));

最新更新