-5

i have an outofbound exception index 1, size 1 i cant seem to find the problem here is my code:

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));

            }
        }
    }
}
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • Looks like Java to me. If not, please tag your question properly. – Felix Kling Mar 05 '15 at 21:59
  • Well presumably `spells.size()` is 1, and you're calling `spells.get(1)` because `c` is `1`. Either that or the equivalent for `spellArea`. Note that the way you're removing items from `spellArea` is pretty dicey - you'll be skipping over values (if you remove element 0, the next element to check is now element 0 again...) – Jon Skeet Mar 05 '15 at 22:01
  • 1
    How you do you `spells.size() >= 5` or `spellArea.size() >= 5`? You don't check that anywhere. – Chad Mar 05 '15 at 22:01
  • 5
    Fundamentally though, you haven't told us where the exception is or what you've tried to do to fix it. You haven't given us a short but complete program demonstrating the problem, so we're basically left guessing. – Jon Skeet Mar 05 '15 at 22:01

1 Answers1

0

I'm going to provide a version of your method which achieves its apparent intent. My hope is that this will at least help you figure out what you wanted to do, if it doesn't solve your issue.

public void removeSpellToGraveyard(ArrayList<SpellCard> spells) {
    for (SpellCard r: spells) {
        if (spellArea.remove(r)) {
            graveyard.add(r);
        }
    }
}
gknicker
  • 5,509
  • 2
  • 25
  • 41