0

reduceクラスのcloseメソッドに出力コレクターがあります。出力コレクターの形式は次のとおりです。<Text, Text>

キーとしてTextname_txtを渡し、値としてTextvalを渡します。

テキストname_txtとテキストvalの両方を出力するとnullではないことがわかりますが、出力にを設定すると、output.collect(name_str、val);でnullポインター例外が発生します。

わかりやすくするために、以下のコードを添付しました。plsは助けます!

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

Where do you set the value of output?

I see you're using the old API (mapred), so you don't have the luxury of a setup method. Instead you'll probably have to add a conditional in your map method:

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 に答える