title: how to handle NullPointerException in this code?
body: <p>I am new at java and i have this exception in my code:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at Course.addStudents(Course.java:31)
      at Third.main(Third.java:28)
  </code></pre>
  
  <p>Course.java</p>
  
  <pre><code>public boolean addStudents(Student newStudent){
       for (Student student : students){
           if (student.getID()== newStudent.getID()){
               return false;
           }
       }
       if(numberOfStudents &lt; capacity){    
           students[numberOfStudents++] = newStudent;
           return true;
       }
       return false;
       }
  </code></pre>
  
  <p>Third.java</p>
  
  <pre><code>c1.addStudents(s1);
  </code></pre>
  
  <p>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??</p>