Cant가 NullPointerException 오류를 떨쳐 버리는 것처럼 보입니다. 지금 약 1 년 동안 코딩하고 있습니다. 어쨌든 !xyz.equals(null)
또는 xyz[0] != null
의 모든 가능한 조합을 시도했지만 해결책을 찾을 수 없습니다. 나는 지금 약 2 시간을 보냈다. 도움을 많이 주시면 감사하겠습니다. 감사.NullPointerException을 어떻게 제거합니까?
public class PedMapReducer extends Reducer<Text, Text, NullWritable, Text>
{
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> ped = new LinkedHashMap<String, String>();
Set<String> s = new LinkedHashSet<String>();
List<String> arr = new ArrayList<String>();
String joined = null;
public void reduce(Text key, Iterable<Text> values, Context context)
{
String [] lines = values.toString().split(",");
if (lines[0] != null && lines[0] == "map_")
{
map.put(lines[1], lines.toString());
}
else if (lines[0] != null && lines[0] == "ped_")
{
ped.put(lines[1], lines.toString());
}
}
public void cleanup(Context context) throws IOException, InterruptedException
{
if(!map.entrySet().equals(null) && !ped.entrySet().equals(null))
{
for (Entry<String, String> entMap: map.entrySet())
{
for(Entry<String, String> entPed: ped.entrySet())
{
if(entMap.getKey().equals(entPed.getKey()))
joined = entMap.getValue() + "," + entPed.getValue();
}
}
context.write(NullWritable.get(), new Text(joined));
}
}
}
스택
14/10/20 16:15:03 INFO mapreduce.Job: Task Id : attempt_1413663101908_0026_r_000110_0, Status : FAILED
Error: java.lang.NullPointerException
at org.apache.hadoop.io.Text.encode(Text.java:450)
at org.apache.hadoop.io.Text.set(Text.java:198)
at org.apache.hadoop.io.Text.<init>(Text.java:88)
at Map_Ped1.PedMapReducer.cleanup(PedMapReducer.java:49)
at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:179)
at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:627)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:389)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:168)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1614)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:163)
는'정리()' –
코드의 라인 NPE를 트리거에 나타납니다 < 초기화 > 새로운 텍스트() 널 포인터 예외의 원인 의미? 전체 스택 추적 표시하기 – Lolo
스택 트레이스에서 코드에서 NPE를 일으키는 라인이 명확하지 않습니다. 이 라인을 가리킬 수 있습니까? – Multisync