mapreduce执行报错:java.lang.NoSuchMethodException:

13/11/07 08:45:08 INFO mapred.JobClient: Task Id : attempt_201311070843_0001_r_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.NoSuchMethodException: com.group2.UserBean.<init>()
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:62)
at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:40)
at org.apache.hadoop.mapreduce.ReduceContext.nextKeyValue(ReduceContext.java:117)
at org.apache.hadoop.mapreduce.ReduceContext.nextKey(ReduceContext.java:92)
at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:175)
at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:572)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:414)
at org.apache.hadoop.mapred.Child$4.run(Child.java:266)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInform
attempt_201311070843_0001_r_000000_0: log4j:WARN No appenders could be found for logger (org.apache.hadoop.hdfs.DFSClient).
attempt_201311070843_0001_r_000000_0: log4j:WARN Please initialize the log4j system properly.


代码如下:
package com.group2;
public class DisGroupCount extends Configured implements Tool
{
public int run(String[] args) throws Exception
{
Job job = new Job(this.getConf());
job.setJarByClass(this.getClass());
job.setJobName("DisGroupCount");
job.setMapperClass(DisGroupMapper.class);
job.setReducerClass(DisGroupReduce.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(UserBean.class);
job.setOutputKeyClass(NullWritable.class);
job.setOutputValueClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job,new Path(args[0]));
FileOutputFormat.setOutputPath(job,new Path(args[1]));
return job.waitForCompletion(true) ? 0 : 1;
}
public static void main(String[] args) throws Exception
{
ToolRunner.run(new DisGroupCount(), args);
}
}

package com.group2;
public class DisGroupMapper extends Mapper<LongWritable,Text,Text,UserBean>
{
protected void map(LongWritable key, Text value,Context context)throws IOException, InterruptedException
{
String[] values = value.toString().split(",");
context.write(new Text(values[0]),new UserBean(new Text(values[1]),new LongWritable(Long.parseLong(values[2]))));
}
}
package com.group2;
public class DisGroupReduce extends Reducer<Text,UserBean,Text,Text>
{
protected void reduce(Text key,Iterable<UserBean> value,Context context) throws IOException, InterruptedException
{
HashSet<Text> tmpSet = new HashSet<Text>();
long sum = 0l;
while(value.iterator().hasNext())
{
UserBean tmp = value.iterator().next();
tmpSet.add(tmp.getEmpNo());
sum += tmp.getSumAmr().get();
}
String outValue = "时间:"+key.toString()+",人数合计:"+tmpSet.size()+",业绩合计:"+sum;
context.write(null,new Text(outValue));
}
}

package com.group2;
public class UserBean implements Writable
{
private Text empNo;
private LongWritable sumAmr;
public UserBean(Text empNo,LongWritable sumAmr)
{
this.empNo = empNo;
this.sumAmr = sumAmr;
}
public void readFields(DataInput input) throws IOException
{
empNo.readFields(input);
sumAmr.readFields(input);
}
public void write(DataOutput output) throws IOException
{
empNo.write(output);
sumAmr.write(output);
}
public Text getEmpNo() {
return empNo;
}
public void setEmpNo(Text empNo) {
this.empNo = empNo;
}
public LongWritable getSumAmr() {
return sumAmr;
}
public void setSumAmr(LongWritable sumAmr) {
this.sumAmr = sumAmr;
}
}

唐半张 - 一句话介绍

赞同来自:

已经解决了。 UserBean 没有默认的构造函数。 加一个默认的构造函数就好了。

要回复问题请先登录注册