0
を減らす私はこのエラー:マップのためのjava.lang.NullPointerExceptionエラープログラム
context.write(新しいテキスト(stringWord)、新しいテキスト(fileNameに))
でファイル名を送信しようmap.javaクラスrecude.java
import java.io.IOException;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
public class Reduce extends Reducer<Text, Text, Text, Text> {
@Override
public void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
MapWritable occurenceInFile = new MapWritable();
for (Text val : values) {
if(occurenceInFile.containsKey(val)) {
occurenceInFile.put(val, new IntWritable(1));
} else {
IntWritable occurence = (IntWritable) occurenceInFile.get(val);
occurenceInFile.put(val, new IntWritable(occurence.get() + 1));
}
sum += 1;
}
String result = key.toString() + " (";
boolean flag = false;
for (Writable filenameWritable : occurenceInFile.keySet()) {
if (flag) {
result += ", ";
}
String filename = ((Text) filenameWritable).toString();
result += filename + "=" + ((IntWritable) occurenceInFile.get(filenameWritable)).toString();
flag = true;
}
result += ")\nTotal occurence of \"" + key + "\": " + Integer.toString(sum);
context.write(key, new Text(result));
}
}
エラーコードこのエラーコードが標準エラー出力
Error: java.lang.NullPointerException
at Reduce.reduce(Reduce.java:18)
at Reduce.reduce(Reduce.java:6)
at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:180)
at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:656)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:394)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:172)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:166)
でショーです私begi私はまだこのエラーを修正する方法がわかりません。
コードの6行目と18行目を見てください。これは単語カウントプログラムですか?混乱のように見えます。私は何かをきれいに書くことが可能だと確信しています。 – duffymo
は、はい、これは全体のプログラムではありませんが、私は –
あなたは間違っていると思った私のmap.javaとwordcount.java(メインクラス)に誤りがないと思います。エラーがあります。 JVMはちょうどそれを明らかにしました。私はこれをもっとはっきりと書くことができると確信しています。 Hadoopで試してみる前に、JDK8ストリームベースのバージョンをお勧めします。あなたがそれをすることができなければ、あなたは大きなハンマーでほとんどチャンスがありません。単純なことをまずやってください。 – duffymo