When writing a mapreduce program, the data transmitted between map and reduce must be of the arraylist type. During debugging and running, the following error occurs:
Java. Lang. runtimeexception: Java. Lang. nosuchmethodexception: org. Apache. hadoop. Io. arraywritable. <init> ()
After querying the API documentation on the official website, you can find the following:
A writable for arrays containing instances of a class. the elements of this writable must all be instances of the same class. if this writable will be the input for a reducer, you will need to create a subclass that sets the value to be of the proper type. for example:Public class intarraywritable extends arraywritable {public intarraywritable () {super (intwritable. Class );}}
It turns out that you need to implement a derived class of the arraywritable class by yourself. When using this class, you only need to implement two constructors.
Public static class textarraywritable extends arraywritable {public textarraywritable () {super (text. class);} public textarraywritable (string [] strings) {super (text. class); text [] texts = new text [Strings. length]; for (INT I = 0; I <strings. length; I ++) {texts [I] = new text (strings [I]);} set (texts );}}
My personal blog: http://www.yancey.info /? P = 188
How to Use arraywritable in mapreduce