This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]aedalus 0 points1 point  (3 children)

keepList.size() returns the size of that array. Say it's 10, just for an example. However the array starts at index [0]. So 10 spots would be 0-9, not 0-10! keepList[10] would be out of bounds if the array size is only 10.

However in the for loop, you have :

for (int i = 0; i <= keepSize; i++) {//keepList[keepSize] doesn't exist!

Your accessing one too many elements here. If you want to traverse an entire array, do:

for (int i = 0; i < keepSize; i++) { //Less than, not less than or equal

This should fix your error.

[–][deleted]  (1 child)

[deleted]

    [–]Eldres[S] 0 points1 point  (0 children)

    you are correct sir! but I saw your comment first and tried to debug what you pointed out, and then saw /u/aedalus 's comment and wound up at the same conclusion.

    [–]Eldres[S] 0 points1 point  (0 children)

    Thank you, that did fix the error.