开发者社区> 问答> 正文

Eclipse中运行Wordcount程序报错

Wordcount程序如下:

import java.io.IOException;
import java.util.Iterator;
import java.util.StringTokenizer;
 
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapred.TextOutputFormat;
 
public class WordCount {
 
    public static class Map extends MapReduceBase implements
            Mapper<LongWritable, Text, Text, IntWritable> {
        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();
 
        public void map(LongWritable key, Text value,
                OutputCollector<Text, IntWritable> output, Reporter reporter)
                throws IOException {
            String line = value.toString();
            StringTokenizer tokenizer = new StringTokenizer(line);
            while (tokenizer.hasMoreTokens()) {
                word.set(tokenizer.nextToken());
                output.collect(word, one);
            }
        }
    }
 
    public static class Reduce extends MapReduceBase implements
            Reducer<Text, IntWritable, Text, IntWritable> {
        public void reduce(Text key, Iterator<IntWritable> values,
                OutputCollector<Text, IntWritable> output, Reporter reporter)
                throws IOException {
            int sum = 0;
            while (values.hasNext()) {
                sum += values.next().get();
            }
            output.collect(key, new IntWritable(sum));
        }
    }
 
    public static void main(String[] args) throws Exception {
        JobConf conf = new JobConf(WordCount.class);
        conf.setJobName("wordcount");
 
        conf.setOutputKeyClass(Text.class);
        conf.setOutputValueClass(IntWritable.class);
 
        conf.setMapperClass(Map.class);
        conf.setCombinerClass(Reduce.class);
        conf.setReducerClass(Reduce.class);
 
        conf.setInputFormat(TextInputFormat.class);
        conf.setOutputFormat(TextOutputFormat.class);
 
        FileInputFormat.setInputPaths(conf, new Path("hdfs://192.168.1.181:9000/user/root/bbs_post2"));
        FileOutputFormat.setOutputPath(conf, new Path("hdfs://192.168.1.181:9000/data/test-out10"));
//        FileInputFormat.setInputPaths(conf, new Path(args[0]));
//        FileOutputFormat.setOutputPath(conf, new Path(args[1]));
        JobClient.runJob(conf);
    }
}

报错信息如下:

log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
 log4j:WARN Please initialize the log4j system properly.
 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
 Exception in thread "main" java.lang.NullPointerException
     at java.lang.ProcessBuilder.start(Unknown Source)
     at org.apache.hadoop.util.Shell.runCommand(Shell.java:445)
     at org.apache.hadoop.util.Shell.run(Shell.java:418)
     at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:650)
     at org.apache.hadoop.util.Shell.execCommand(Shell.java:739)
     at org.apache.hadoop.util.Shell.execCommand(Shell.java:722)
     at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:631)
     at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:421)
     at org.apache.hadoop.fs.FilterFileSystem.mkdirs(FilterFileSystem.java:277)
     at org.apache.hadoop.mapreduce.JobSubmissionFiles.getStagingDir(JobSubmissionFiles.java:125)
     at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:348)
     at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1285)
     at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1282)
     at java.security.AccessController.doPrivileged(Native Method)
     at javax.security.auth.Subject.doAs(Unknown Source)
     at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1548)
     at org.apache.hadoop.mapreduce.Job.submit(Job.java:1282)
     at org.apache.hadoop.mapred.JobClient$1.run(JobClient.java:562)
     at org.apache.hadoop.mapred.JobClient$1.run(JobClient.java:557)
     at java.security.AccessController.doPrivileged(Native Method)
     at javax.security.auth.Subject.doAs(Unknown Source)
     at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1548)
     at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:557)
     at org.apache.hadoop.mapred.JobClient.submitJob(JobClient.java:548)
     at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:833)
     at WordCount.main(WordCount.java:71)

展开
收起
爵霸 2016-06-02 09:37:45 2307 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关镜像