Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解决java.lang.ArrayindexOutOfBoundsException_Java_Indexoutofboundsexception - Fatal编程技术网

解决java.lang.ArrayindexOutOfBoundsException

解决java.lang.ArrayindexOutOfBoundsException,java,indexoutofboundsexception,Java,Indexoutofboundsexception,有人能帮我解决这个错误吗 package bigdata.tp1; 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.hado

有人能帮我解决这个错误吗

package bigdata.tp1;
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.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.log4j.BasicConfigurator;

public class WordCount {
    public static void main(String[] args) throws Exception {
        BasicConfigurator.configure();
        Configuration conf = new Configuration();
        Path inputPath=new Path(args[0]);
        Path outputPath=new Path(args[1]);// ligne 16
        Job job = Job.getInstance(conf, "wordcount");
        job.setJarByClass(WordCount.class);
        job.setMapperClass(MyMapper.class);
        job.setCombinerClass(MyReducer.class);
        job.setReducerClass(MyReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        FileInputFormat.addInputPath(job, inputPath);
        FileOutputFormat.setOutputPath(job,outputPath);
        if (!job.waitForCompletion(true))
            return;
    }

}

线程“main”java.lang.ArrayIndexOutOfBoundsException中的异常: 索引1超出长度为1的范围 main(WordCount.java:16)


看起来您正试图访问第二个comandline参数,但只提供了一个参数。
在访问这些参数之前,请检查参数计数。

如果需要两个程序参数,则需要先检查它们

public static void main(String[] args) throws Exception {
   if(args.length != 2){
       throw new IllegalArgumentException("Exact 2 arguments needed");
   }
   //your code here
}

我忘了在程序的参数中添加第二个参数,即:src/main/resources/output。
所以在运行->编辑设置下。。。→ + → 应用程序)我必须在程序参数下添加src/main/resources/output

是的,我忘了在程序参数中添加第二个参数,即:src/main/resources/output谢谢