gpt4 book ai didi

hadoop - 获取空指针异常

转载 作者:可可西里 更新时间:2023-11-01 16:30:05 25 4
gpt4 key购买 nike

目前我正在尝试学习 map reduce 中的二级排序,但在运行我的映射器时出现空指针异常错误。我正在使用这个 link 但是在运行代码时出现错误。这是我的 callStack。

16/06/18 13:34:53 INFO mapreduce.Job: Task Id : attempt_1466235357420_0007_m_000000_0, Status : FAILED Error: java.lang.NullPointerException at SecondartSort.SecondarySortSample1.SecondarySortMapper.map(SecondarySortMapper.java:22) at SecondartSort.SecondarySortSample1.SecondarySortMapper.map(SecondarySortMapper.java:1) at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145) at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:784) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341) at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:163) at java.security.AccessController.doPrivileged(Native Method) at 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

请多多指教

谢谢普拉迪普

最佳答案

您实际上并没有创建任何类变量。这些都将是未初始化的:

private CustomTextInt nameDepname;
private Text name;
private Text departmentName;
private IntWritable sal;

例如 name 应该是这样的:

private Text name = new Text();

关于hadoop - 获取空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37894790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com