2013-05-28 6 views
0

이 문제가 해결되지 않아 코드에 무엇이 잘못된 것인지 잘 모릅니다. 제발 도와주세요. 당신이 그것을 사용하는 점에서 여전히 null이 될 수있는 다른 스레드에서의 HashMap를로드하는 경우Error : java.lang.nullpointerexception

List<DataPoint> listPoints; 
if((listPoints = hashMap.get(h)) == null) { 
    listPoints = new ArrayList<DataPoint>(); 
    DataPoint point = new DataPoint((int)songId, i); 
    listPoints.add(point); 
    hashMap.put(h, listPoints); 
} 
+3

logcat을 게시하면 어떤 줄이 'NPE'인지 알 수 있습니다. 'hashMap'이'null'이라는 좋은 기회가 있습니다 – codeMagic

+0

아마도'hashMap'이 초기화되지 않았습니까? – MrSmith42

+2

나머지 코드를 게시하고 실제로 NullPointer를 던지는 행은 무엇입니까? – draksia

답변

0

:이 코드에 error java.lang.nullpointerexception을 얻었다. 또한 h도 null이 될 수 있습니다. 조금 더 자세히 그 조각에서

0
if((listPoints = hashMap.get(h)) == null) 
{ 
    listPoints = new ArrayList<DataPoint>(); 
    DataPoint point = new DataPoint((int)songId, i); 
    listPoints.add(point); 
    hashMap.put(h, listPoints); 
} 

좋은 것, 당신이 NullPointerException을 받고있을 것입니다 유일한 선은 hashMap.get()hashMap.put() 전화입니다. 내 말은 hashMap은 초기화되지 않았으므로 null입니다. 따라서 hashMap.get()으로 전화하면 예외가 발생합니다.

0

사용중인 HashMap (예 : ConcurrentHashMap)의 구현이 null 키를 허용하지 않을 수 있습니다. h가 null이면 NullPointerException이 발생합니다.

관련 문제