Exception in thread "main" java.lang.NullPointerException
at Course.dropStudent(Course.java:95)
at CourseTester.main(CourseTester.java:59)
I'm writing a Course class that works with a Student class(that i'm not allowed to modify) and have been provided a CourseTester class to ensure everything works properly. I've been making my way through it but i noticed that i'm now getting that error. It's happening when i try to compare a Student id from the CourseTester class to the student id's already in the array. The entire program is over 300 lines so i'll just try to copy in the parts where the problem is.
Fist part is from the Course class that i am writing
public boolean dropStudent(Student student) {
boolean dropped = false;
int targetIndex = 0;
Student[] newRoster = new Student[roster.length];
for (int count = 0; count < roster.length; count++) {
if (roster[count].getID() == (student.getID())) {//line95
targetIndex = count;
dropped = true;
}
}
Second part is from the CourseTester that was provided.
// drop student not on roster or waitlist
studentToDrop = studentsInSchool[14]; // WW
dropped = course.dropStudent(studentToDrop);//line 59
System.out.println("For " + studentToDrop.getName() + ", drop method should return false (student
is not enrolled): \t" + dropped);
System.out.println("\nCourse should still contain AA, DD, EE, FF, and GG on the course roster (in
any order) and HH, JJ, KK, and MM on the waitlist (in that exact order).");
System.out.println("\n" + course + "\n");
Note, I have to use Arrays. The goal here is to find remove a student from the roster(drop from course). I need to do this by searching for his student ID number.