目前我正在尝试在map map中学习Secondary Sort,但在运行mapper时遇到空指针异常错误。我正在使用此link 但是在运行代码时我得到了错误。这是我的callStack。
16/06/18 13:34:53 INFO mapreduce.Job:任务ID:attempt_1466235357420_0007_m_000000_0,状态:未通过 错误:java.lang.NullPointerException 在SecondartSort.SecondarySortSample1.SecondarySortMapper.map(SecondarySortMapper.java:22) 在SecondartSort.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) at java.security.AccessController.doPrivileged(Native Method) 在javax.security.auth.Subject.doAs(Subject.java:415)
我的映射器代码是:
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
善意的建议
由于 sPradeep
答案 0 :(得分:2)
您实际上并未创建任何类变量。这些都将是未初始化的:
private CustomTextInt nameDepname;
private Text name;
private Text departmentName;
private IntWritable sal;
例如name
应如下所示:
private Text name = new Text();