2011-08-22 66 views
7

我正在爲Hadoop 0.20.2編寫一個自定義InputFormat,並且正在運行到一個NoSuchMethodException中,我無法擺脫。我開始:自定義MapReduce輸入格式 - 找不到構造函數

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 

inititially得到的錯誤和網上調查後,我想這可能是我沒有一零參數的構造函數,所以我加了一個:

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(); 
    } 
} 

這也不能工作,所以我加了那個任意數量的對象的第二構造函數:

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(); 
    } 
} 

仍然收到相同的錯誤,並且迄今爲止一直未能找到解決方案。

滿電流源:http://pastebin.com/2XyW5ZSS

+0

只要刪除你的構造函數,就不需要在你的輸入格式中有一個構造函數。 –

回答

7

你ConnectionInputFormat類應該是靜態的。非靜態嵌套類爲每個構造函數添加了一個隱含的「this」。因此,除非類聲明爲靜態,否則無參數構造函數實際上具有不可見的參數。

+2

昨晚經過一番艱苦的調試後,得出了類似的結論。發送給構造函數的「this」是父類(TestInputJob)。然後該類將「this」或TestInputJob的構造函數中的參數數量(無)與嵌套類ConnectionInputFormat中的構造函數中的參數數量進行比較。由於它們明顯不同,因此失敗了。 – BugsPray

+0

@BugsPray:這就是我想說的。你的措辭更好。 –