在写MR的时候遇到一个类似下面的错误信息:
java.lang.RuntimeException: java.lang.NoSuchMethodException: com.xxx.thriftoutput.RecommendResult.<init>()
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:131)
at org.apache.hadoop.fs.shell.Display$TextRecordInputStream.<init>(Display.java:226)
at org.apache.hadoop.fs.shell.Display$Text.getInputStream(Display.java:152)
at org.apache.hadoop.fs.shell.Display$Cat.processPath(Display.java:101)
at org.apache.hadoop.fs.shell.Command.processPaths(Command.java:306)
at org.apache.hadoop.fs.shell.Command.processPathArgument(Command.java:278)
at org.apache.hadoop.fs.shell.Command.processArgument(Command.java:260)
at org.apache.hadoop.fs.shell.Command.processArguments(Command.java:244)
at org.apache.hadoop.fs.shell.Command.processRawArguments(Command.java:190)
at org.apache.hadoop.fs.shell.Command.run(Command.java:154)
at org.apache.hadoop.fs.FsShell.run(FsShell.java:287)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:84)
at org.apache.hadoop.fs.FsShell.main(FsShell.java:340)
Caused by: java.lang.NoSuchMethodException: com.xxx.thriftoutput.RecommendResult.<init>()
at java.lang.Class.getConstructor0(Class.java:2810)
at java.lang.Class.getDeclaredConstructor(Class.java:2053)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:125)
... 13 more
由报错信息可知应该与RecommendResult有关,而这个类是我自定义的Writable类,根据init方式和reflection可知,是与其初始化有关,后来查资料可知,在自定义writable的时候需要注意,反射过程中需要调用无参构造方法,所以只要在自定义的writable类中加入默认的构造函数即可