OutOfBoundException索引:1,大小:1

时间:2015-03-05 21:58:43

标签: java indexoutofboundsexception

我有一个outofbound异常索引1,大小为1 我似乎无法找到问题 这是我的代码:

public void removeSpellToGraveyard(ArrayList<SpellCard> spells){
    for(int c=0; c<5 ; c++ ){
        SpellCard r = spells.get(c);
        for(int i=0; i<5;i++){
            if(spellArea.get(i) == r){
                graveyard.add(spellArea.remove(i));

            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我将提供您的方法版本,以实现其明显的意图。我希望这至少可以帮助你弄清楚你想做什么,如果它没有解决你的问题。

public void removeSpellToGraveyard(ArrayList<SpellCard> spells) {
    for (SpellCard r: spells) {
        if (spellArea.remove(r)) {
            graveyard.add(r);
        }
    }
}