改错之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();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值