【发布时间】:2014-04-23 16:39:59
【问题描述】:
使用此代码
System.out.println("New Mark Entry\n--------------" + "\n\nEnter the description (up to 40 characters will be displayed):");
name = TextIO.getlnString();
if (name.length() > 40) {
name = name.substring(0,40);
}
System.out.println("What was the assignment out of?");
totalMark = TextIO.getlnDouble();
System.out.println("What was the students mark?");
mark = TextIO.getlnDouble();
System.out.println("What was the weight of this assignement?");
weight = TextIO.getlnDouble();
input = 1;
int openSpot = 0;
for(int i = 0; i < markbook.length; i++) {
if(markbook[i].getAssignment(name) == null) { // java.lang.NullPointerException is thrown here
openSpot = i;
break;
}
}
markbook[openSpot] = new Mark(name, totalMark, mark, weight);
break;
导致抛出 java.lang.NullPointerException。我对如何解决这个问题感到有点困惑。如果有人可以帮助或指出我正确的方向,将不胜感激
【问题讨论】:
-
您检查过
markbook[i]中的内容吗? -
堆栈跟踪通常会有所帮助。
-
在此代码中放置断点..即
name,markbook[i] 或类似的案例... -
你初始化markbook[]了吗?