0

我在 reduce 类的 close 方法中有输出收集器。输出收集器的格式是<Text, Text>

我将 Text name_txt 作为键传递,将 Text val 作为值传递。

我发现 Text name_txt 和 Text val 通过打印它们都不为空,但是当我在输出中设置时,我在 output.collect(name_str, val); 处得到空指针异常;

为了清楚起见,我附上了下面的代码。请帮忙!

private OutputCollector<Text, Text> output;

public void close() throws IOException {          
  for(int i = 0; i<arraylist.size(); i++)
  {
    String name = arraylist.get(i).getToken();
    Text name_txt = new Text(name);
    System.out.println("name_txt: "+name_txt);
    Text val = new Text("hi");
    output.collect(name_txt, val);         
  }         
}
4

1 回答 1

0

你在哪里设置输出的值?

我看到您使用的是旧 API(mapred),因此您没有设置方法的奢侈。相反,您可能必须在 map 方法中添加条件:

void map(K1 key, V1 value, OutputCollector<K2, V2> output, Reporter reporter)
  throws IOException {
  if (this.output == null) {
    this.output = output;
  }

  // your current map implementation goes here..
}
于 2012-07-26T01:37:55.127 回答