title: Replace nodes in double linked list
body: <p>Given two double linked lists I'm supposed to change, not just the elements, but the nodes of one of the lists so that the sum in the same positions equals a certain number.</p>
  
  <pre><code>public void repair(int num){
      Node list1 = head1;
      Node right = head2;
  
      for(int i = 0; i&lt;size; i++){
          int element = num - list1.element;
          Node p = right.previous;
          Node s = right.next;
          right = new Node(element, null, null);
  
          p.next = right;
          right.previous = p;
          right.next = s;
          s.previous = right;
  
          list1 = list1.next;
          right = right.next;
      }
  }
  </code></pre>
  
  <p>size = size of both list which is the same.
  I've tried a lot of things but it always gives me nullpointerexception on p.next = right and s.previous = right;</p>
  
  <p>I don't understand why it gives me this error. Can someone explain and show me a way of solving this?</p>