在编写mapreduce程序时,map和reduce之间传递的数据需要是arraylist类型的,在调试运行时遇到了这样的一个错误:
java.lang.runtimeexception: java.lang.nosuchmethodexception: org.apache.hadoop.io.arraywritable.<init>()
经查询官网api文档后发现这样的一段话:
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); } }
原来是要自己实现一个arraywritable类的派生类,使用时只要实现两个构造函数即可
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); } }
如对本文有疑问, 点击进行留言回复!!
android用Popup弹出窗(PopupWindow的使用方式)
ionic3 打包 Could not get resource ‘https://jcenter.bintray.com/com/google/zxing/core/3.2.1/core-3.2.1
NullPointerException: Attempt to invoke virtual method ‘android.content.res.XmlResourceParser androi
网友评论