日志大魔王 2019-11-21 00:13 采纳率: 0%
浏览 2792

运行mapredurce出现Method threw 'java.lang.IllegalStateException' exception. Cannot evaluate org.apache.hadoop.mapreduce.Job.toString()

执行下述代码后在,创建job后会有上述异常,但是可以执行到最后,但是job没有提交上去执行,在历史里也看不到有执行记录求帮助新手o(╥﹏╥)o。
package MapReducer;

import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
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.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.StringTokenizer;

/**

  • @Describe MapReducer第一个读取文档并计数
  • @Author zhanglei
  • @Date 2019/11/18 22:53
    **/
    public class WordCountApp extends Configured implements Tool {

    public int run(String[] strings) throws Exception {
    String input_path="hdfs://192.168.91.130:8020/data/wc.txt";
    String output_path="hdfs://192.168.91.130:8020/data/outputwc";
    Configuration configuration = getConf();
    final FileSystem fileSystem = FileSystem.get(new URI(input_path),configuration);
    if(fileSystem.exists(new Path(output_path))){
    fileSystem.delete(new Path(output_path),true);
    }
    Job job = Job.getInstance(configuration,"WordCountApp");
    job.setJarByClass(WordCountApp.class);
    job.setMapperClass(WordCountMapper.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    job.setReducerClass(WordCountReducer.class);
    job.setInputFormatClass(TextInputFormat.class);
    Path inpath = new Path(input_path);
    FileInputFormat.addInputPath(job,inpath);
    job.setOutputFormatClass(TextOutputFormat.class);
    Path outpath = new Path(output_path);
    FileOutputFormat.setOutputPath(job,outpath);
    return job.waitForCompletion(true) ? 0:1;
    }

    //继承
    public static class WordCountMapper extends Mapper{
    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 {
    Text t = value;
    StringTokenizer itr = new StringTokenizer(value.toString());
    while(itr.hasMoreTokens()){
    word.set(itr.nextToken());
    context.write(word,one);
    }
    }
    }

    public static class WordCountReducer extends Reducer{
    private final static IntWritable res= new IntWritable(1);
    public void reduce(Text key,Iterable values,Context context) throws IOException, InterruptedException {
    int sum = 0;
    for(IntWritable val:values){
    sum+=val.get();
    }
    res.set(sum);
    context.write(key,res);
    }
    }

    public static void main(String[] args) throws Exception {
    int exitCode = ToolRunner.run(new WordCountApp(), args);
    System.exit(exitCode);
    }

}

  • 写回答

2条回答 默认 最新

  • 头上化佛 2021-05-17 18:28
    关注

    我也遇到了相似的问题,不知道是怎么回事?

    评论

报告相同问题?

悬赏问题

  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案