小编War*_*een的帖子

ArrayList的HashMap导致nullpointerexception

我有一个ArrayLists的HashMap用于值,但是当我添加ArrayLists时HashMap保持为空,然后当我尝试get()ArrayList时抛出NullPointerException.非常困惑.

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--;
        }
    }
Run Code Online (Sandbox Code Playgroud)

java arraylist hashmap nullpointerexception

0
推荐指数
1
解决办法
737
查看次数

错误:使用gcc与'six'冲突的类型

接收错误:尝试编译时"六"的冲突类型.

void main(){
    const int k = 4;
    six(&k);
}

float * six(const int *x)
{
    float *p =  malloc(sizeof(float));
    *p = (float)*x;
    return p;
}
Run Code Online (Sandbox Code Playgroud)

c gcc

0
推荐指数
2
解决办法
1549
查看次数

标签 统计

arraylist ×1

c ×1

gcc ×1

hashmap ×1

java ×1

nullpointerexception ×1