Guide to arraywritable use in MapReduce _java

Source: Internet
Author: User
Tags static class

When you write a mapreduce program, the data that is passed between map and reduce needs to be ArrayList type, and you encounter one of these errors during debugging run:

Java.lang.runtimeexception:java.lang.nosuchmethodexception:org.apache.hadoop.io.arraywritable.<init> ()

After querying the official website API document to discover such a passage:

A writable for arrays containing instances of a class. The elements of this writable must all is instances of the same class. If This writable'll be is the input for a reducer, you'll need to create a subclass that sets the value of the prop ER type.  For Example:public class Intarraywritable extends Arraywritable {public intarraywritable () {super (intwritable.class);} }

The original is to implement a arraywritable class of derived classes, when used as long as the implementation of two constructors can

public static class Textarraywritable extends Arraywritable {public
 textarraywritable () {
 super (Text.class); c3/>} 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);
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.