I'm writing a custom InputFormat for Hadoop 0.20.2 and am running into a NoSuchMethodException I can't get rid of. I started with:

我正在为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();
    }
}

I got this error when running:

运行时出现此错误:

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

After getting the error inititially and researching online, I thought it might be that I didn't have a zero-argument constructor, so I added one:

在初始化错误并在线研究之后,我认为可能是因为我没有零参数构造函数,所以我添加了一个:

public class ConnectionInputFormat extends FileInputFormat<Text, Connection> {

    public ConnectionInputFormat() {
        System.out.println("NetflowInputFormat Constructor");
    }

    @Override
    public RecordReader<Text, Connection> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        return new ConnectionRecordReader();
    }
}

That didn't work either, so I added a second constructor that took in any number of objects:

这也没用,所以我添加了第二个构造函数,它接受了任意数量的对象:

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, Connection> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        return new ConnectionRecordReader();
    }
}

Still getting the same error, and have been so far unsuccessful in finding a solution.

仍然得到相同的错误,并且到目前为止找不到解决方案是不成功的。

Full current source: http://pastebin.com/2XyW5ZSS

全电流源:http://pastebin.com/2XyW5ZSS

1 个解决方案

#1


7

Your ConnectionInputFormat class should be static. Non-static nested classes have an implied 'this' added to every constructor. Thus, your no-arg constructor actually has an invisible argument unless the class is declared static.

您的ConnectionInputFormat类应该是静态的。非静态嵌套类在每个构造函数中都添加了隐含的“this”。因此,除非将类声明为static,否则no-arg构造函数实际上具有不可见的参数。

更多相关文章

  1. 使用Java中的Scala:将函数作为参数传递
  2. “不是抽象的,也不重写抽象的方法”错误
  3. 关于Javascript中声明变量、函数的笔记
  4. 异步执行多个任务并在JavaScript函数中返回第一个成功的结果

随机推荐

  1. 关于Android(安卓)intent的知识
  2. EditeText标签字体大小设置 是否可编辑
  3. Android安装以及Eclipse插件(Google Andr
  4. Android调用本机地图APP
  5. Android Non-UI to UI Thread Communicat
  6. Ubuntu 试用Android L版本
  7. android 之摄像头
  8. pointer location
  9. android开源新闻小程序、3D翻转公告效果
  10. Android基本组件