title: Merge two sorted linked list null pointer and inputs work only for one instance
body: <p>The first line contains an integer t, the number of test cases.</p>
  <p>The format for each test case is as follows:</p>
  <p>The first line contains an integer n, the length of the first linked list.
  The next line contains n integers, the elements of the first linked list.
  The next line contains an integer m, the length of the second linked list.
  The next line contains m integers, the elements of the second linked list.</p>
  <p>my code:</p>
  <pre><code>static void merge(MergeTowLiLi lili1, MergeTowLiLi lili2, MergeTowLiLi lili3){
          Node temp1 = lili1.head;
          Node temp2 = lili2.head;
          Node temp3 = lili3.head;
          while(temp1 != null || temp2 != null){
              if(temp1.data &lt;= temp2.data){
                  lili3.append(temp1.data);
                  temp1 = temp1.next;
              }else{
                  lili3.append(temp2.data);
                  temp2 = temp2.next;
              }
          }
          while(temp3!=null){
              temp3 = temp3.next;
          }
          if(temp1.next == null){
              while(temp2 != null){
                  lili3.append(temp2.data);
                  temp2 = temp2.next;
              }
          }
          if(temp2.next == null){
              while(temp1 != null){
                  lili3.append(temp1.data);
                  temp1 = temp1.next;
              }
          }
          lili3.printList();
      }
      public static void main(String[] args){
          MergeTowLiLi lili1 = new MergeTowLiLi();
          MergeTowLiLi lili2 = new MergeTowLiLi();
          MergeTowLiLi lili3 = new MergeTowLiLi();
          Scanner sc = new Scanner(System.in);
          int t = sc.nextInt();
          for(int i=0;i&lt;t;i++) {
              int n = sc.nextInt();
              for (int j = 0; j &lt; n; j++) {
                  int l1 = sc.nextInt();
                  lili1.append(l1);
              }
              int m = sc.nextInt();
              for (int k = 0; k &lt; m; k++) {
                  int l2 = sc.nextInt();
                  lili2.append(l2);
              }
              merge(lili1, lili2, lili3);
          }
      }
  </code></pre>
  <p>i cannot understand where is the null pointer exception
  Exception in thread &quot;main&quot; java.lang.NullPointerException: Cannot read field &quot;data&quot; because &quot;temp1&quot; is null
  kindly help thanks in advance.</p>