I am new at java and i have this exception in my code:
Exception in thread "main" java.lang.NullPointerException
at Course.addStudents(Course.java:31)
at Third.main(Third.java:28)
Course.java
public boolean addStudents(Student newStudent){
for (Student student : students){
if (student.getID()== newStudent.getID()){
return false;
}
}
if(numberOfStudents < capacity){
students[numberOfStudents++] = newStudent;
return true;
}
return false;
}
Third.java
c1.addStudents(s1);
I have tried the solve it but didnt achieve. I searched for it and I guess the problem is initializing. Is it true? if it is, I dont know how to handle with that, any idea??
studentsinitialized? Are all its elements initialized?