欢迎投稿

今日深度:

改错之Hadoop,

改错之Hadoop,


java.lang.Exception: java.lang.ClassCastException

java.lang.Exception: java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be cast to org.apache.commons.lang.math.LongRange
at org.apache.hadoop.mapred.LocalJobRunnerJob.runTasks(LocalJobRunner.java:462)atorg.apache.hadoop.mapred.LocalJobRunnerJob.run(LocalJobRunner.java:522)
Caused by: java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be cast to org.apache.commons.lang.math.LongRange
at cn.tarena.mr2.SecondMrMapper.map(SecondMrMapper.java:1)

public class SecondMrMapper extends Mapper<LongRange, Text, DoubleMr, NullWritable>{

@Override
protected void map(LongRange key, Text value, Mapper<LongRange, Text, DoubleMr, NullWritable>.Context context)
        throws IOException, InterruptedException {
    String line=value.toString();
    String[] data=line.split(" ");
    DoubleMr mr=new DoubleMr();
    mr.setName(data[0]);
    mr.setProfit(Integer.parseInt(data[1]));
    context.write(mr, NullWritable.get());
}

}

改正:

public class SecondMrMapper extends Mapper<LongWritable, Text, DoubleMr, NullWritable>{

@Override
protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, DoubleMr, NullWritable>.Context context)
        throws IOException, InterruptedException {
    String line=value.toString();
    String[] data=line.split(" ");
    DoubleMr mr=new DoubleMr();
    mr.setName(data[0]);
    mr.setProfit(Integer.parseInt(data[1]));
    context.write(mr, NullWritable.get());
}

}

java.lang.Exception: java.io.EOFException

java.lang.Exception: java.io.EOFException
at org.apache.hadoop.mapred.LocalJobRunnerJob.runTasks(LocalJobRunner.java:462)atorg.apache.hadoop.mapred.LocalJobRunnerJob.run(LocalJobRunner.java:529)
Caused by: java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:197)
at java.io.DataInputStream.readUTF(DataInputStream.java:609)
at java.io.DataInputStream.readUTF(DataInputStream.java:564)
at cn.tarena.domain.HttpAppHost.readFields(HttpAppHost.java:57)

@Override
public void write(DataOutput out) throws IOException {

        out.writeUTF(reportTime);
        out.writeUTF(cellid);
        out.writeInt(appType);
        out.writeInt(appSubType);
        out.writeUTF(userIp);
        out.writeInt(userPort);
        out.writeUTF(appServerIp);
        out.writeInt(appServerPort);
        out.writeUTF(host);
        out.writeInt(attempts);
        out.writeInt(accepts);
        out.writeLong(trafficUL);
        out.writeLong(trafficDL);
        out.writeLong(retranUL);
        out.writeLong(retranDL);
        out.writeLong(transDelay);

}

@Override
public void readFields(DataInput in) throws IOException {
    this.reportTime = in.readUTF();
    this.cellid = in.readUTF();
    **this.appType = in.readInt();
    this.appType = in.readInt();**
    this.appSubType = in.readInt();
    this.userIp = in.readUTF();
    this.userPort = in.readInt();
    this.appServerIp = in.readUTF();
    this.appServerPort = in.readInt();
    this.host = in.readUTF();
    this.attempts = in.readInt();
    this.accepts = in.readInt();
    this.trafficUL = in.readLong();
    this.trafficDL = in.readLong();
    this.retranUL = in.readLong();
    this.retranDL = in.readLong();
    this.transDelay = in.readLong();
}

改错:变量顺序必须匹配(第6行)

@Override
public void write(DataOutput out) throws IOException {

        out.writeUTF(reportTime);
        out.writeUTF(cellid);
        out.writeInt(appType);
        out.writeInt(appSubType);
        out.writeUTF(userIp);
        out.writeInt(userPort);
        out.writeUTF(appServerIp);
        out.writeInt(appServerPort);
        out.writeUTF(host);
        out.writeInt(attempts);
        out.writeInt(accepts);
        out.writeLong(trafficUL);
        out.writeLong(trafficDL);
        out.writeLong(retranUL);
        out.writeLong(retranDL);
        out.writeLong(transDelay);

}

@Override
public void readFields(DataInput in) throws IOException {
    this.reportTime = in.readUTF();
    this.cellid = in.readUTF();
    this.appType = in.readInt();
    this.appSubType = in.readInt();
    this.userIp = in.readUTF();
    this.userPort = in.readInt();
    this.appServerIp = in.readUTF();
    this.appServerPort = in.readInt();
    this.host = in.readUTF();
    this.attempts = in.readInt();
    this.accepts = in.readInt();
    this.trafficUL = in.readLong();
    this.trafficDL = in.readLong();
    this.retranUL = in.readLong();
    this.retranDL = in.readLong();
    this.transDelay = in.readLong();
}

www.htsjk.Com true http://www.htsjk.com/Hadoop/41267.html NewsArticle 改错之Hadoop, java.lang.Exception: java.lang.ClassCastException java.lang.Exception: java.lang.ClassCastException: org.apache.hadoop.io. LongWritable cannot be cast to org.apache.commons.lang.math. LongRange at org.apache.hadoop.mapred...
相关文章
    暂无相关文章
评论暂时关闭