所以我要做的是从gui上的复选框中读取一个值,如果未选中该值,则将+1添加到变量numInspected。
一旦完成所有步骤,我在尝试通过另一个方法传递变量时会得到NullPointerException。
inspected = display.readInt("inspected");
if(inspected <= 0) {
numInspected += 1;
System.out.println(numInspected); //Testing purposes
}
}
writeSummary(numInspected);
这是writeSummary的代码:
private void writeSummary (int numInspected) {
report.writeLine("Needs Inspection - " + numInspected);
}
这是我得到的错误:
java.lang.NullPointerException at Assign4.Inspection.writeSummary(Inspection.java:117)at Assign4.Inspection。(Inspection.java:58)at Assign4.Inspection.main(Inspection.java:121)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:606)at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)