我有java.lang.ArrayIndexOutOfBoundsException

我有java.lang.ArrayIndexOutOfBoundsException,java,for-loop,Java,For Loop,在预测游戏中,两个或两个以上的玩家试图预测一系列即将到来的体育比赛的得分。然后根据下面列出的类别之和评估每个玩家的预测。这些描述使用以下变量: S1:第1队的实际得分 S2:第二队的实际得分 P1:一个球员对1队的预测得分 P2:球员对第二队的预测得分 但是我有异常java.lang.ArrayIndexOutOfBoundsException public void game() { int s1, s2, p1, p2, winner, team1, team2, pointSpre

在预测游戏中,两个或两个以上的玩家试图预测一系列即将到来的体育比赛的得分。然后根据下面列出的类别之和评估每个玩家的预测。这些描述使用以下变量:

S1:第1队的实际得分

S2:第二队的实际得分

P1:一个球员对1队的预测得分

P2:球员对第二队的预测得分

但是我有异常
java.lang.ArrayIndexOutOfBoundsException

public void game() {
    int s1, s2, p1, p2, winner, team1, team2, pointSpread, total = 0;

    int testCase = scan.nextInt();

    for (int k = 0; k < testCase; k++) {

        int p = scan.nextInt();
        int c = scan.nextInt();

        int[]result = new int[p];
        String[]pName = new String[p];

        for (int i = 0; i < p; i++) {
            pName[i] = scan.next();

            for (int j = 0; j < c; j++) {
                p1 = scan.nextInt();
                p2 = scan.nextInt();
                s1 = 20;
                s2 = 13;

                if (s1 > s2 && p1 > p2) {
                    winner = 10;
                }
                if (s1 < s2 && p1 < p2) {
                    winner = 10;
                } else {
                    winner = 0;
                }

                team1 = 5 - Math.abs(s1 - p1);
                team2 = 5 - Math.abs(s2 - p2);
                pointSpread = 5 - Math.abs(p1 - p2)-(s1 - s2);

                total += winner + team1 + team2 + pointSpread;
                result[i] = total;
            }
        }

        //compare players scores
        int max = result[0], playerNo = 0;
        for (int m = 1; m <= p; m++)//this line error
            if (max < result[m]) {
                max = result[m];
                playerNo = m;
            }

        System.out.println(pName[playerNo]);
    }
}
publicsvoid游戏(){
int s1、s2、p1、p2、获胜者、团队1、团队2、积分差,总计=0;
int testCase=scan.nextInt();
for(int k=0;ks2&&p1>p2){
获胜者=10;
}
if(s1对于(int m=1;m将错误行更改为
for(int m=1;不可能重复的@Arc676),请仅在检查事实后进行评论。索引0已由循环外部的用户处理。抱歉。注释超出了截取的代码的默认大小,看起来代码在那里结束(在循环之前)。我的错误。