错误:java.lang.ClassCastException:wordCountTest.wordCountTest无法强制转换为org.apache.hadoop.mapreduce.Mapper

错误:java.lang.ClassCastException:wordCountTest.wordCountTest无法强制转换为org.apache.hadoop.mapreduce.Mapper,java,hadoop,mapreduce,oozie,oozie-coordinator,Java,Hadoop,Mapreduce,Oozie,Oozie Coordinator,我是一个尝试使用java学习MapReduce的初学者。我正在尝试使用oozie coordinator运行单词计数示例。我的演员选错了。如果有人能帮我解决这个错误那就太好了 错误:java.lang.ClassCastException:wordCountTest.wordCountTest 无法强制转换为org.apache.hadoop.mapreduce.Mapper“ 以下是我的WordCountTest.java代码片段: package wordCountTest; import

我是一个尝试使用java学习MapReduce的初学者。我正在尝试使用oozie coordinator运行单词计数示例。我的演员选错了。如果有人能帮我解决这个错误那就太好了

错误:java.lang.ClassCastException:wordCountTest.wordCountTest 无法强制转换为org.apache.hadoop.mapreduce.Mapper“

以下是我的WordCountTest.java代码片段:

package wordCountTest;

import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
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.output.FileOutputFormat;

public class WordCountTest {
 public static class TokenizerMapper
            extends Mapper<Object, Text, Text, IntWritable>{
  private final static IntWritable one = new IntWritable(1);
  private Text word = new Text();
  public void map(Object key, Text value, Context context
        ) throws IOException, InterruptedException {
   StringTokenizer itr = new StringTokenizer(value.toString());
   while (itr.hasMoreTokens()) {
    word.set(itr.nextToken());
    context.write(word, one);
   }
  }
 }
 public static class IntSumReducer
            extends Reducer<Text,IntWritable,Text,IntWritable> {
  private IntWritable result = new IntWritable();    
  public void reduce(Text key, Iterable<IntWritable> values,
                           Context context
        ) throws IOException, InterruptedException {
   int sum = 0;
   for (IntWritable val : values) {
    sum += val.get();
   }
   result.set(sum);
   context.write(key, result);
  }
 }
 public static void main(String[] args) throws Exception {
  Configuration conf = new Configuration();
  Job job = new Job(conf,"WordCount");
  job.setJarByClass(WordCountTest.class);
  job.setMapperClass(TokenizerMapper.class);
  job.setCombinerClass(IntSumReducer.class);
  job.setReducerClass(IntSumReducer.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);
 }
}
package-wordCountTest;
导入java.io.IOException;
导入java.util.StringTokenizer;
导入org.apache.hadoop.conf.Configuration;
导入org.apache.hadoop.fs.Path;
导入org.apache.hadoop.io.IntWritable;
导入org.apache.hadoop.io.Text;
导入org.apache.hadoop.mapreduce.Job;
导入org.apache.hadoop.mapreduce.Mapper;
导入org.apache.hadoop.mapreduce.Reducer;
导入org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
导入org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
公共类WordCountTest{
公共静态类令牌映射器
扩展映射器{
私有最终静态IntWritable one=新的IntWritable(1);
私有文本字=新文本();
公共无效映射(对象键、文本值、上下文
)抛出IOException、InterruptedException{
StringTokenizer itr=新的StringTokenizer(value.toString());
而(itr.hasMoreTokens()){
set(itr.nextToken());
上下文。写(单词,一);
}
}
}
公共静态类IntSumReducer
伸缩减速机{
私有IntWritable结果=新的IntWritable();
public void reduce(文本键、Iterable值、,
语境
)抛出IOException、InterruptedException{
整数和=0;
for(可写入值:值){
sum+=val.get();
}
结果集(总和);
编写(键、结果);
}
}
公共静态void main(字符串[]args)引发异常{
Configuration conf=新配置();
Job Job=新作业(conf,“WordCount”);
job.setJarByClass(WordCountTest.class);
setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
addInputPath(作业,新路径(args[0]);
setOutputPath(作业,新路径(args[1]);
系统退出(作业等待完成(真)?0:1;
}
}
另外,my workflow.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<workflow-app xmlns="uri:oozie:workflow:0.1" name="map-reduce-wf">
 <start to="mr-node" />
 <action name="mr-node">
  <map-reduce>
   <job-tracker>${jobTracker}</job-tracker>
   <name-node>${nameNode}</name-node>
   <configuration>
    <property>
     <name>mapred.mapper.new-api</name>
     <value>true</value>
    </property>
    <property>
     <name>mapred.reducer.new-api</name>
     <value>true</value>
    </property>
    <property>
     <name>mapred.job.queue.name</name>
     <value>${queueName}</value>
    </property>
    <property>
     <name>mapreduce.map.class</name>
     <value>wordCountTest.WordCountTest.TokenizerMapper</value>
    </property>
    <property>
     <name>mapreduce.reduce.class</name>
     <value>wordCountTest.WordCountTest.IntSumReducer</value>
    </property>
    <property>
     <name>mapreduce.combine.class</name>
     <value>wordCountTestEmr.WordCountTest.IntSumReducer</value>
    </property>
    <property>
     <name>mapred.output.key.class</name>
     <value>org.apache.hadoop.io.Text</value>
    </property>
    <property>
     <name>mapred.output.value.class</name>
     <value>org.apache.hadoop.io.IntWritable</value>
    </property>
    <property>
     <name>mapred.input.dir</name>
     <value>/user/ahegde/testemr/InputData/</value>
    </property>
    <property>
     <name>mapred.output.dir</name>
     <value>/user/ahegde/testemr/OutputData</value>
    </property>
   </configuration>
  </map-reduce>
 <ok to="end" />
 <error to="fail" />
 </action>
  <kill name="fail">
   <message>Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
  </kill>
  <end name="end" />
 </workflow-app>

${jobTracker}
${nameNode}
mapred.mapper.new-api
真的
mapred.reducer.new-api
真的
mapred.job.queue.name
${queueName}
mapreduce.map.class
wordCountTest.wordCountTest.TokenizerMapper
mapreduce.reduce.class
wordCountTest.wordCountTest.IntSumReducer
mapreduce.combine.class
WordCountTester先生WordCountTest.IntSumReducer
mapred.output.key.class
org.apache.hadoop.io.Text
mapred.output.value.class
org.apache.hadoop.io.IntWritable
mapred.input.dir
/用户/ahegde/testemr/InputData/
mapred.output.dir
/用户/ahegde/testemr/OutputData
映射/减少失败,错误消息[${wf:errorMessage(wf:lastErrorNode())}]

您可能需要更改Oozie配置,因为这些是内部静态类:

<property>
    <name>mapreduce.map.class</name>
    <value>wordCountTest.WordCountTest$TokenizerMapper</value>
</property>

mapreduce.map.class
wordCountTest.wordCountTest$TokenizerMapper

更改是将
更改为
$

您可能需要更改Oozie配置,因为这些是内部静态类:

<property>
    <name>mapreduce.map.class</name>
    <value>wordCountTest.WordCountTest$TokenizerMapper</value>
</property>

mapreduce.map.class
wordCountTest.wordCountTest$TokenizerMapper

更改是将
更改为
$

请检查此项,为什么要使mapper和reducer类保持静态?请删除map类和reducer类的静态,如果可能的话,请将它们取出并在同一个包中创建为单独的类,然后再试一次。请检查这一点,为什么要将mapper和reducer类设置为静态?请删除map类和reduce类的static,如果可能的话,请将它们取出并在同一个包中创建为单独的类,然后再试一次。