【问题标题】:Getting ArrayIndexOutOfBoundsException: 3 while executing Hadoop Pragram on cloudera在cloudera上执行Hadoop Pragram时出现ArrayIndexOutOfBoundsException:3
【发布时间】:2016-03-16 02:20:48
【问题描述】:

在 cloudera linux 机器上我得到 ArrayIndexOutOfBoundsException: 3 .

我无法理解为什么这个程序会出现这个异常,只有其他人对我很好。

public class TransactionCount extends Configured implements Tool {

@Override
public int run(String[] arg0) throws Exception {


    if(arg0.length<2)
    {
        System.out.println("Please provide inpt and output directory properly");
        return -1;
    }
    JobConf conf=new JobConf(com.ankur.MRpractice.TransactionCount.class); 

    FileInputFormat.setInputPaths(conf, new Path(arg0[0]),new Path(arg0[1],new Path(arg0[2])));
    FileOutputFormat.setOutputPath(conf,new Path(arg0[3]));

    conf.setMapperClass(TransMapper.class);
    conf.setReducerClass(TransReducer.class);

    conf.setMapOutputKeyClass(Text.class);
    conf.setMapOutputValueClass(IntWritable.class);

    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);

    conf.setPartitionerClass(TransPartioner.class);
    conf.setNumReduceTasks(4);

    JobClient.runJob(conf);

    return 0;

}

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

}

【问题讨论】:

  • 我正在运行的命令是: hadoop jar TransactionCount.jar com.ankur.MRpractice.TransactionCount /user/mapreduce/tscInput/transactionCount /user/mapreduce/tscOutput 这是: hadoop jar jar_name Driver_Class input_file output_directory Getting Exception at line: FileInputFormat.setInputPaths(conf, new Path(arg0[0]),new Path(arg0[1],new Path (arg0[2])));

标签: java hadoop dictionary reduce


【解决方案1】:

我认为在 if 条件下你应该使用 arg0.length 而不是 arg0.length

【讨论】:

  • 我试过了,但它不起作用。如果我使用你的解决方案,那么我会收到来自 if 条件的消息。
【解决方案2】:

换行,

FileInputFormat.setInputPaths(conf, new Path(arg0[0]),new Path(arg0[1],new Path(arg0[2])));

FileInputFormat.setInputPaths(conf, new Path(arg0[0]),new Path(arg0[1]),new Path(arg0[2]));

请尝试,我希望它会有所帮助,args1 的右括号在 arg2 之后关闭,这会产生问题。

【讨论】:

  • Prashant 即使在更正错误后仍然出现相同的异常。
  • 我有其他类的相同驱动程序代码,它工作正常。 public int run(String[] arg0) throws Exception { if(arg0.length
  • 这个修改后你重建jar了吗?如果是,请粘贴完整的异常,这将有助于解决错误。
  • 线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 2 at com.ankur.MRpractice.TransactionCount.run(TransactionCount.java:24) at org.apache.hadoop.util.ToolRunner.run (ToolRunner.java:65) 在 org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:79) 在 com.ankur.MRpractice.TransactionCount.main(TransactionCount.java:46) 在 sun.reflect.NativeMethodAccessorImpl。在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 在的invoke0(Native Method)
  • sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在 a.lang.reflect.Method.invoke(Method.java:597) 在 org.apache.hadoop.util.RunJar。 main(RunJar.java:186)
猜你喜欢
  • 2011-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-29
相关资源
最近更新 更多