Java ArrayIndexOutOfBound

后端 未结 4 707
感情败类
感情败类 2020-12-22 13:43

I am currently working on a student project and everytime I get this error: ArrayIndexOutOfBoundsException: 7. Can someone see where it occurs and how I can fix

4条回答
  •  清酒与你
    2020-12-22 14:36

    Currently you are incrementing the index at the end of the array, causing the program to go outside the bounds of the array. Therefore you should change...

    if(c <= Playerlist.length)
    {
        c++;
    }
    

    ...to...

    if(c < Playerlist.length)
    {
        c++;
    }
    

提交回复
热议问题