title: Increase each node's value in a binary tree by 1
body: <p>So the exercise I am trying to do is:</p>
  
  <p>Write a recursive function to increment by one the value for every node in the binary tree pointed at by "root" then return the modified tree. Assume that nodes store integer values. (-1 means a NULL pointer)</p>
  
  <p>The code I have so far is:</p>
  
  <pre><code>public BinNode BTinc(BinNode root)
  {
  
      if (root.right == null &amp;&amp; root.left == null){
          root.setValue(root.value() + 1);
          return root;
      }
  
      if (root.left != null) {
          root.left.setValue(root.left.value() + 1);
          return BTinc(root.left);
      }
  
      if (root.right != null) { 
          root.right.setValue(root.right.value() + 1);
          return BTinc(root.right);   
      } 
  
  
      return root;
  
  }
  </code></pre>
  
  <p>The problem I am having so far occurs when the root being passed in is -1, in which I get a null pointer exception. I am a bit confused on how this is happening. Is it because I am trying to access the right and left pointers of the null pointer? </p>