目前我正在尝试学习MapReduce中的二次排序,但是在运行Map程序时出现了一个空指针异常错误。我使用这个链接,但在运行代码时,我得到了错误。这是我的呼叫堆栈。
2018年6月16日13:34:53 info mapreduce.job:任务id:尝试\u 1466235357420 \u 0007 \u m \u 0000000,状态:失败错误:secondartsort.secondarysortsample1.secondarysortmapper.map(secondarysortmapper)处的java.lang.nullpointerexception。java:22)在secondarySort.secondarysortsample1.secondarysortmapper.map(secondarysortmapper。java:1)在org.apache.hadoop.mapreduce.mapper.run(mapper。java:145)在org.apache.hadoop.mapred.maptask.runnewmapper(maptask。java:784)在org.apache.hadoop.mapred.maptask.run(maptask。java:341)在org.apache.hadoop.mapred.yarnchild$2.run(yarnchild。java:163)位于javax.security.auth.subject.doas(subject)的java.security.accesscontroller.doprivileged(本机方法)。java:415)
我的Map程序代码是:
public class SecondarySortMapper extends Mapper<LongWritable , Text, CustomTextInt, IntWritable> {
private CustomTextInt nameDepname;
private Text name;
private Text departmentName;
private IntWritable sal;
public void map (LongWritable key , Text value , Context context) throws IOException , InterruptedException{
String[] line = value.toString().split(",");
//String depName = line[3];
String Fullname =line[2]+line[1];
name.set(Fullname);
departmentName.set(line[3]);
nameDepname.set(name,departmentName);
sal.set(Integer.parseInt(line[4]));
context.write(nameDepname, sal);
}
}
数据文件为:
1,kumar,sunil,enginering,2200
2,mishra,sunil,enginering,1200
3,arora,karan,mech,1200
4,sharma,vivek,physics,2300
5,koushik,vivek,physics,1350
6,sindhu,armaan,math,2310
7,arora,armaan,math,500
8,yadav,pooja,mech,1800
9,kuthi,pooja,math,1600
10,arora,sunil,physics,1450
11,mishra,karan,enginering,3400
12,chandra,manish,physics,2300
善意的建议
谢谢斯普拉德
1条答案
按热度按时间pzfprimi1#
实际上,您没有创建任何类变量。这些都将被取消初始化:
例如
name
应该是这样的: