This keeps throwing a NullPointerException
after the if statement, do any of you have an idea why?
public void deleteCourse() {
Scanner courseInput = new Scanner(System.in);
System.out.println("Enter coursename to delete");
String deleteInput = courseInput.nextLine();
System.out.println("check");
int pos = this.findPosition(deleteInput);
System.out.println(pos);
if (pos != -1) {
students[pos].setName(students[students.length - 1].getName());
students[pos].setGrade(students[students.length - 1].getGrade());
}
}
public int findPosition(String deleteInput) {
int i;
for (i = 0; i < students.length; i++) {
if (deleteInput.equals(students[i].getName())) {
return i;
}
}
return -1;
}