I have that function where i want the user to pick a number of all schedules to delete one.
My logic for delete is to find the i
that I want to delete and then swap the last one schedule of my array with the i
one, and then the last one to be null.
当我测试我的程序时, 当我想删除我最后一个阵列的时候, 我看到了一切正常, 但是当我试图删除其它东西时, 日蚀中会出现一个错误。
Exception in thread "main" java.lang.NullPointerException I cant figure out what s happening. I have reviewed my code a lot of times.
public void ScheduleDelete(){
StandardInputRead readDeleteSchedule = new StandardInputRead();
int deleteScheduleNum =readDeleteSchedule.readPositiveInt("Enter the schedule number you want to delete: ");
for(int i=0;i<scheduleSize;i++){
if(deleteScheduleNum==this.scheduleList[i].getScheduleNum()){
this.scheduleList[i]= this.scheduleList[this.scheduleSize-1];
this.scheduleList[i].setScheduleNum(i);
this.scheduleList[this.scheduleSize-1]= null;
}
}
this.scheduleSize--;
}