title: How to find node by name in Binary Search Tree in Java
body: <hr>
  
  <p>I write method to find node of student records by the first and last name of student in Binary Search Tree</p>
  
  <p>This is the code of the method in class Binary Search Tree</p>
  
  <pre><code>private Student root;
  
  public Student findNodeName(String firstname,String lastname) {
  
      return findNodeName(root,firstname,lastname);
  
  }
  
  private Student findNodeName(Student student,String firstname,String 
   lastname){
  
  
      if (student == null) {
          return null;
      }
  
  
      else if (firstname.equals(student.getFirstName())
              &amp;&amp;lastname.equals(student.getLastName())) {   
          return student;
      }
  
      else
      {
          if(student.getLeft()!= null)  
          return findNodeName(student.getLeft(),firstname,lastname);
  
      else 
          return findNodeName(student.getRight(),firstname,lastname);
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p>And This code in main class</p>
  
  <pre><code>//declare object of class universitydbmsBST
   universitydbmsBST universitydbmsbst;
  
  if (command.equals("SEARCHNAME") == true) {
  
          //variables to read from input file
          String firstname = input.next();
          String lastname = input.next();
  
          //variable used to check if the student is already in BSt or not 
          Student student =null;
  
  
         //print if the student found or not
          if((student = 
               universitydbmsbst.findNodeName(firstname,lastname))!=null){
  
              output.println("SEARCHNAME Command");
              output.println("Found:  ID "+student.getID()+",  
              "+student.getFirstName()+" "+student.getLastName());
  
          }
  
  
          else {
  
              output.println("SEARCHNAME Command");
               output.println(student.getFirstName()+" 
               "+student.getLastName()+" was not found in 
                FCITbook.");
  
          }
  
      }
  </code></pre>
  
  <hr>
  
  <p>But I have a problem when I do run it appears NullPointerException</p>
  
  <p>Can anyone help me?</p>