NullPointerExcpetion在类级别阵列Java上使用for循环时

时间:2016-01-23 19:50:35

标签: java for-loop nullpointerexception mean

我刚开始Java编程。我正在尝试创建一个类方法,它将在for循环中的同一个类中使用数组。但是当我尝试运行程序时抛出NullPointerException。有人可以指出这里有什么问题吗?谢谢!

public class Judge {
    double [] judgeScoreArray;
    double judgeMean = getMean();
    //Method to calculate mean of an array
    public double getMean(){
        double sum = 0;
        //***NullPointerException Thrown at the next line***
        for (int i = 0; i <judgeScoreArray.length; i++){ 
        sum = sum + judgeScoreArray[i];
        }
        return sum/((judgeScoreArray.length));
    }

    public Judge(){
    judgeScoreArray = new double [7];
    for (int i = 0; i < 7; i++){
        judgeScoreArray[i] = 0;
    }
}

0 个答案:

没有答案