eclipse—hadoop中线程“main”java.lang.arrayindexoutofboundsexception中的异常:1

ogq8wdun  于 2021-07-13  发布在  Hadoop
关注(0)|答案(1)|浏览(554)

这个问题在这里已经有了答案

mapreduce java.lang.arrayindexoutofboundsexception:0(1个答案)
上个月关门了。
我正在尝试使用hadoop计算文本文件中每个单词的频率。我已附上密码。

  1. package sub4;
  2. import java.io.IOException;
  3. import java.util.*;
  4. import org.apache.hadoop.fs.Path;
  5. import org.apache.hadoop.conf.*;
  6. import org.apache.hadoop.io.*;
  7. import org.apache.hadoop.mapreduce.*;
  8. import org.apache.hadoop.mapreduce.Reducer.Context;
  9. import org.apache.hadoop.mapreduce.lib.input.*;
  10. import org.apache.hadoop.mapreduce.lib.output.*;
  11. public class count {
  12. public static class Map extends Mapper<LongWritable, Text, Text, IntWritable>{
  13. //private final static IntWritable one = new IntWritable(1);
  14. IntWritable one = new IntWritable(1);
  15. //private Text word = new Text();
  16. public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
  17. String[] line = value.toString().split(",");
  18. for(String lines:line) {
  19. context.write(new Text(lines),one);
  20. }
  21. }
  22. }
  23. public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
  24. public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int sum = 0;
  25. for (IntWritable val : values) {
  26. sum += val.get();
  27. }
  28. context.write(key, new IntWritable(sum));
  29. }
  30. }
  31. public static void main(String[] args) throws Exception {
  32. Configuration conf = new Configuration();
  33. Job job = new Job(conf, "count");
  34. job.setJarByClass(count.class);
  35. job.setOutputKeyClass(Text.class);
  36. job.setOutputValueClass(IntWritable.class);
  37. job.setMapperClass(Map.class);
  38. job.setReducerClass(Reduce.class);
  39. job.setInputFormatClass(TextInputFormat.class);
  40. job.setOutputFormatClass(TextOutputFormat.class);
  41. FileInputFormat.addInputPath(job, new Path(args[0]));
  42. FileOutputFormat.setOutputPath(job, new Path(args[1]));
  43. job.waitForCompletion(true);
  44. } ``
  45. }

我保存了这段代码,并试图通过右键单击它并按export使它成为eclipse中的jar文件。之后,我转到终端并键入hadoopjar/home/user/wcount.jar sub4.count//wc/output。
这个错误来了

  1. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
  2. at sub4.count.main(count.java:51)
  3. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  4. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  5. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  6. at java.lang.reflect.Method.invoke(Method.java:606)
  7. at org.apache.hadoop.util.RunJar.main(RunJar.java:156)
l0oc07j2

l0oc07j21#

代码需要在命令行上输入文件名和输出文件名。
你没有提供。

相关问题