2017-02-21 78 views
0

我试图执行在Eclipse中的Hadoop的字计数程序执行单词计数程序,我收到以下错误:得到错误,而在Hadoop中

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 
at WordCount.run(WordCount.java:22) 
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) 
at WordCount.main(WordCount.java:35) 

我从网上复制的代码和代码似乎然而罚款参考我在这里粘贴代码:

WordCount.java

import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.conf.*; 
import org.apache.hadoop.io.*; 
import org.apache.hadoop.mapred.*; 
import org.apache.hadoop.util.*; 

public class WordCount extends Configured implements Tool{ 
     public int run(String[] args) throws Exception 
     { 
     //creating a JobConf object and assigning a job name for  identification purposes 
     JobConf conf = new JobConf(getConf(), WordCount.class); 
     conf.setJobName("WordCount"); 

     //Setting configuration object with the Data Type of output Key and Value 
     conf.setOutputKeyClass(Text.class); 
     conf.setOutputValueClass(IntWritable.class); 

     //Providing the mapper and reducer class names 
     conf.setMapperClass(WordCountMapper.class); 
     conf.setReducerClass(WordCountReducer.class); 
     //We wil give 2 arguments at the run time, one in input path and other is output path 
     Path inp = new Path(args[0]); 
     Path out = new Path(args[1]); 
     //the hdfs input and output directory to be fetched from the command line 
     FileInputFormat.addInputPath(conf, inp); 
     FileOutputFormat.setOutputPath(conf, out); 

     JobClient.runJob(conf); 
     return 0; 
    } 

    public static void main(String[] args) throws Exception 
    { 
     // this main function will call run method defined above. 
    int res = ToolRunner.run(new Configuration(), new WordCount(),args); 
     System.exit(res); 
    } 

}

+0

您可以参考以下链接中的字数统计执行/提交示例http://ybhavesh.blogspot.in/2015/11/ways-to-write-traditional-word.html – Bhavesh

回答

0

似乎你没有通过适当的命令行参数。

+0

如果您在谈论提供缺少的代码,然后我提供以下代码片断 - WordCountMapper.java和WordCountReducer.java – Lamar

+0

如何执行程序以及传递的命令行参数Path inp = new Path(args [0]); Path out = new Path(args [1]); –

+1

您可以参考以下链接中的字数统计执行/提交示例http://ybhavesh.blogspot.in/2015/11/ways-to-write-traditional-word.html – Bhavesh