title: Finding max in binarytree and return that node
body: <p>As the title says I need help finding max in a binarytree. Im trying to do it with recursion.</p>
  
  <p>The nodes have a instance variable of frequency which updates if the element in the node is a duplicate in the tree and it is that maximum value im trying to reach but I just get a nullpointerexception. this is my code:</p>
  
  <pre><code>private Node getMaxFreq(Node node){
      Node left = null;
      Node right = null;
      if(node == null){
          System.out.println("tree is empty");
      }
      if(node.compareTo(node.left) &lt;= 0){
          getMaxFreq(node.left);
      }
      else{
           left = node;
      }
      if(node.compareTo(node.right) &lt;= 0){
          getMaxFreq(node.right);
      }
      else{
          right = node;
      }
  
      if(left.compareTo(right) &gt; 0){
          return left;
      }
      else{
          return right;
      }
  
  
  }
  /**
   * method to find the node with highest frequency in tree.
   * @return node with highest frequency.
   */
  public void getMaxFreq(){
      Node temp = root;
      System.out.println(getMaxFreq(temp));
  }
  
  //Node class
  public class Node implements Comparable&lt;Node&gt; {
      String word;
      int freq;
      Node left;
      Node right;
  
      Node(String word) {
          this.word = word;
          freq = 1;
  
      }
  
      public String toString() {
          return word + " occurs " + freq + " times.";
      }
  
  
      public int compareTo(Node other) {
  
          return Integer.compare(this.freq, other.freq);
      }
  
  }
  </code></pre>
  
  <p>Please help me!!!</p>