Well, you try to debug it and find the value of variable currentIndex. May be some code changing the currentIndex value.