값에 대한 ArrayList의 HashMap을 가지고 있지만 ArrayList를 추가 할 때 HashMap이 비어 있고 ArrayList를 가져 오려고하면 NullPointerException이 throw됩니다. 매우 혼란.nullpointerexception이 발생하는 ArrayList의 HashMap
Random rand = new Random();
HashMap<String,ArrayList<Integer>> hands = new HashMap<String,ArrayList<Integer>>();
HashMap<Integer, Boolean> deck = new HashMap<Integer, Boolean>();
for(int x=0;x<4;x++){
for(int y=0;y<4;y++){
hands.put(x+SUITS[x], new ArrayList<Integer>());
}
}
for(int x=0;x<4;x++){
for(int y=0;y<13;y++){
int randCard = rand.nextInt(52)+1;
if(!deck.containsKey(randCard)){
deck.put(randCard, true);
hands.get(x+cardSuit(randCard)).add(randCard);
}else y--;
}
}
_cardSuit() _ 메소드를 보지 못해도 문제를 해결하기가 쉽지 않지만 얻을 때 사용하는 키에 매핑 된 값이 없음이 분명합니다. – jahroy
코드를 보면 참조를 취소하려고 시도하는 키가있을 것이라고 기대할 필요가 없습니다. _put_을 사용할 때 사용하는 키는 _get_ 사용할 때 사용하는 키와 완전히 다릅니다. – jahroy