我正在爲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
只要刪除你的構造函數,就不需要在你的輸入格式中有一個構造函數。 –