java – 自定义MapReduce输入格式 – 找不到构造函数
发布时间:2020-12-15 03:11:38 所属栏目:Java 来源:网络整理
导读:我正在为Hadoop 0.20.2编写一个自定义的InputFormat,并且遇到NoSuchMethodException我无法摆脱.我开始时: public class ConnectionInputFormat extends FileInputFormatText,Connection { @Override public RecordReaderText,Connection createRecordReader
我正在为Hadoop 0.20.2编写一个自定义的InputFormat,并且遇到NoSuchMethodException我无法摆脱.我开始时:
public class ConnectionInputFormat extends FileInputFormat<Text,Connection> { @Override public RecordReader<Text,Connection> createRecordReader(InputSplit split,TaskAttemptContext context) throws IOException,InterruptedException { return new ConnectionRecordReader(); } } 运行时出现此错误: Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodException: testingground.TestInputJob$ConnectionInputFormat.<init>() at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115) at org.apache.hadoop.mapred.JobClient.writeNewSplits(JobClient.java:882) at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:779) at org.apache.hadoop.mapreduce.Job.submit(Job.java:432) at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:447) at testingground.TestInputJob.run(TestInputJob.java:141) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:79) at testingground.TestInputJob.main(TestInputJob.java:156) Caused by: java.lang.NoSuchMethodException: testingground.TestInputJob$ConnectionInputFormat.<init>() at java.lang.Class.getConstructor0(Class.java:2706) at java.lang.Class.getDeclaredConstructor(Class.java:1985) at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:109) ... 8 more Java Result: 1 在初始化错误并在线研究之后,我认为可能是因为我没有零参数构造函数,所以我添加了一个: public class ConnectionInputFormat extends FileInputFormat<Text,Connection> { public ConnectionInputFormat() { System.out.println("NetflowInputFormat Constructor"); } @Override public RecordReader<Text,InterruptedException { return new ConnectionRecordReader(); } } 这也没用,所以我添加了第二个构造函数,它接受了任意数量的对象: public class ConnectionInputFormat extends FileInputFormat<Text,Connection> { public ConnectionInputFormat() { System.out.println("NetflowInputFormat Constructor"); } public ConnectionInputFormat(Object... o) { System.out.println("NetflowInputFormat Constructor"); } @Override public RecordReader<Text,InterruptedException { return new ConnectionRecordReader(); } } 仍然得到相同的错误,并且迄今为止找不到解决方案是不成功的. 全电流源:http://pastebin.com/2XyW5ZSS 解决方法
您的ConnectionInputFormat类应该是静态的.非静态嵌套类在每个构造函数中都添加了隐含的“this”.因此,除非将类声明为static,否则no-arg构造函数实际上具有不可见的参数.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- java – 为什么从无限循环切换到TimerTask会导致CPU使用率下
- JAVA 时间差距,两个时间相差多少天,时,分,秒
- java – 从ZipInputStream获取特定文件
- Java获取真实的IP地址--转载
- Java8新特性之再见Permgen_动力节点Java学院整理
- 如何从Netbeans Navigator窗口中删除getter和setter
- java – 在单个流上组合allMatch,noneMatch和anyMatch
- Mac OS下安装mvn
- java – “不能在源代码级别下面打开类型为String的值..”错
- java:网络编程(UDP (DatagramSocket和DatagramPacket)正