我已经看到线程已经解决了这个错误,但不知何故,解决方案对我没有帮助。 我正在运行以下代码:
public class WordCount
{
public static class MyMapper extends Mapper<LongWritable,Text,Text,IntWritable>
{
final static IntWritable one=new IntWritable(1);
Text word=new Text();
public void map(LongWritable key,Text Value,Context context) throws IOException,InterruptedException
{
String line=Value.toString();
StringTokenizer itr=new StringTokenizer(line);
while (itr.hasMoreTokens())
{
word.set(itr.nextToken());
context.write(word, one);
}
}
}
public static class MyReducer extends Reducer<Text,IntWritable,Text,IntWritable>{
public void reduce(Text Key,Iterable<IntWritable> Values,Context context) throws IOException,InterruptedException
{
int sum=0;
for (IntWritable value:Values)
{
sum=sum+value.get();
}
context.write(Key, new IntWritable(sum));}
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException
{
//Job job=new Job();
Configuration conf=new Configuration();
Job job=new Job(conf,"Word Count");
job.setJarByClass(WordCount.class);
job.setMapperClass(MyMapper.class);
job.setReducerClass(MyReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job,new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
}
它具有正确格式的主要方法。 当我试图运行它时,它会给我以下错误。
**hadoop jar MyTesting-0.0.1-SNAPSHOT.jar MyPackage.WordCount <Input> <Output>**
Exception in thread "main" java.lang.NoSuchMethodException: MyPackage.WordCount.main([Ljava.lang.String;)
at java.lang.Class.getMethod(Class.java:1670)
at org.apache.hadoop.util.RunJar.run(RunJar.java:215)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)