我刚开始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;
}
}