我的问题已经让我把头发扯了好几天了。如您所见,我将 printlns 放在那里,以便检查错误发生的位置。查看表中的数据后,在最后一个数据块之后发生空指针异常。为什么我的代码不能阻止它再次循环?
public void prepare(int sheet, Students [] gradeSpecific, Students [] mcl)
{
String [] useableCandidates;
useableCandidates = new String [200];//school never has more than 40 candidates therefore 200 is more than enough
int i= 0;
if(sheet==1)
{
while(!gradeSpecific[i].getFirst_name().equals(null) && !gradeSpecific[i].getSurname().equals(null))
{
if(useableCandidates[i]==null)
{useableCandidates[i]= new String();}
System.out.println(gradeSpecific[i].getFirst_name()+gradeSpecific[i].getSurname());
useableCandidates[i]= gradeSpecific[i].getFirst_name()+" , "+gradeSpecific[i].getSurname();
System.out.println(useableCandidates[i]);
i++;
}
}
else
{
while(!mcl[i].getFirst_name().equals(null) || !mcl[i].getSurname().equals(null))
{
useableCandidates[i]= mcl[i].getFirst_name()+" , "+mcl[i].getSurname();
i++;
}
}
}