[英]Why am I getting a null pointer exception here?
I am using java. 我正在使用Java。 The second line of this code is getting a null pointer exception.
这段代码的第二行得到一个空指针异常。
double gpa = 0.0;
gpa = grads[index].calculateGPA();
return gpa;
grads is an array of Graduate objects. 研究生是一系列的研究生对象。 I have tested this method in a JUnitTest and it works fine.
我已经在JUnitTest中测试了此方法,并且效果很好。 I have also tested calculateGPA().
我还测试了calculateGPA()。 Only when I run the program there is an error.
只有当我运行程序时,才会出现错误。
The error could be caused by one of the following possibilities: 该错误可能是由以下可能性之一引起的:
grads
is null
. grads
为null
。 index
is null
. index
为null
。 grads[index]
is null
. grads[index]
为null
。 calculateGPA()
is raising a null pointer exception. calculateGPA()
引发空指针异常。 Use your debugger to find out which of these possibilities it is, and take it from there. 使用调试器找出其中的可能性,然后从那里获取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.