java.lang.NoSuchMethodException: MapReduce.WordCount$MyMapper.<br>()


今日YARNプラットフォームでプログラムをテストしました.wordcount:
package MapReduce;

import java.io.IOException;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.mapreduce.lib.partition.HashPartitioner;

public class WordCount
{
     public static String path1 = "hdfs://hadoop11:9000/dirdata";// HDFS 
     public static String path2 = "hdfs://hadoop11:9000/worddir";
     public static void main(String[] args) throws Exception
     {
         Configuration conf = new Configuration();
         conf.set("fs.defaultFS", "hdfs://hadoop11:9000");
         FileSystem fileSystem = FileSystem.get(conf);// HDFS 
         if(fileSystem.exists(new Path(path2)))
         {
             fileSystem.delete(new Path(path2), true);
         }
         Job job = Job.getInstance(conf);
         job.setJarByClass(WordCount.class);

         FileInputFormat.setInputPaths(job, new Path(path1));
         job.setInputFormatClass(TextInputFormat.class);
         job.setMapperClass(MyMapper.class);
         job.setMapOutputKeyClass(Text.class);
         job.setMapOutputValueClass(LongWritable.class);

         job.setNumReduceTasks(1);
         job.setPartitionerClass(HashPartitioner.class);


         job.setReducerClass(MyReducer.class);
         job.setOutputKeyClass(Text.class);
         job.setOutputValueClass(LongWritable.class);
         job.setOutputFormatClass(TextOutputFormat.class);
         FileOutputFormat.setOutputPath(job, new Path(path2));
         job.waitForCompletion(true);

     }    
     public  class MyMapper extends Mapper<LongWritable, Text, Text, LongWritable>
     {
        protected void map(LongWritable k1, Text v1,Context context)throws IOException, InterruptedException
        {

                 String[] splited = v1.toString().split("\t");
                 for (String string : splited)
                {
                     context.write(new Text(string),new LongWritable(1L));
                }
        }     
     }
     public  class MyReducer extends Reducer<Text, LongWritable, Text, LongWritable>
     {
        protected void reduce(Text k2, Iterable<LongWritable> v2s,Context context)throws IOException, InterruptedException
        {
                 long sum = 0L;
                 for (LongWritable v2 : v2s)
                {
                    sum += v2.get();
                }
                context.write(k2,new LongWritable(sum));
        }
     }
}

実行結果:
Error: java.lang.RuntimeException: java.lang.NoSuchMethodException: MapReduce.WordCount$MyMapper.<init>()
        at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:131)
        at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:722)
        at org.apache.hadoop.mapred.MapTask.run(MapTask.java:340)
        at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:167)
        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:1556)
        at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:162)
Caused by: java.lang.NoSuchMethodException: MapReduce.WordCount$MyMapper.<init>()
        at java.lang.Class.getConstructor0(Class.java:2800)
        at java.lang.Class.getDeclaredConstructor(Class.java:2043)
        at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:125)
        ... 7 more

長い間探していました:やっとMyMapperクラスとMyReducerクラスの前にstaticを忘れたことに気づきました.それに加えて、プログラムが正しく実行されました.
package MapReduce;

import java.io.IOException;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.mapreduce.lib.partition.HashPartitioner;

public class WordCount
{
     public static String path1 = "hdfs://hadoop11:9000/dirdata";// HDFS 
     public static String path2 = "hdfs://hadoop11:9000/worddir";
     public static void main(String[] args) throws Exception
     {
         Configuration conf = new Configuration();
         conf.set("fs.defaultFS", "hdfs://hadoop11:9000");
         FileSystem fileSystem = FileSystem.get(conf);// HDFS 
         if(fileSystem.exists(new Path(path2)))
         {
             fileSystem.delete(new Path(path2), true);
         }
         Job job = Job.getInstance(conf);
         job.setJarByClass(WordCount.class);

         FileInputFormat.setInputPaths(job, new Path(path1));
         job.setInputFormatClass(TextInputFormat.class);
         job.setMapperClass(MyMapper.class);
         job.setMapOutputKeyClass(Text.class);
         job.setMapOutputValueClass(LongWritable.class);

         job.setNumReduceTasks(1);
         job.setPartitionerClass(HashPartitioner.class);


         job.setReducerClass(MyReducer.class);
         job.setOutputKeyClass(Text.class);
         job.setOutputValueClass(LongWritable.class);
         job.setOutputFormatClass(TextOutputFormat.class);
         FileOutputFormat.setOutputPath(job, new Path(path2));
         job.waitForCompletion(true);

     }    
     public  static  class MyMapper extends Mapper<LongWritable, Text, Text, LongWritable>
     {
        protected void map(LongWritable k1, Text v1,Context context)throws IOException, InterruptedException
        {

                 String[] splited = v1.toString().split("\t");
                 for (String string : splited)
                {
                     context.write(new Text(string),new LongWritable(1L));
                }
        }     
     }
     public  static class MyReducer extends Reducer<Text, LongWritable, Text, LongWritable>
     {
        protected void reduce(Text k2, Iterable<LongWritable> v2s,Context context)throws IOException, InterruptedException
        {
                 long sum = 0L;
                 for (LongWritable v2 : v2s)
                {
                    sum += v2.get();
                }
                context.write(k2,new LongWritable(sum));
        }
     }
}