title: NullPointerException when adding node objects to an ArrayList
body: <p>I'm getting a <code>NullPointerException</code> when I try to run this code.  I've assigned <code>Nodes</code> 2,3,and 4 as children nodes to <code>Node1</code>.  I tried to create a method that will go through all the children nodes in Node1 and return the list.  I'm not sure what I'm doing wrong.</p>
  
  <pre><code>public class TestingArrays2 {
  
      List&lt;Node&gt; myList1;
      List&lt;Node&gt; myList2;
      List&lt;Node&gt; myList3;
      List&lt;Node&gt; myList4;
  
      private Node Node1;
      private Node Node2;
      private Node Node3;
      private Node Node4;
  
      public TestingArrays2() {
          myList1 = new ArrayList&lt;Node&gt;();
          myList2 = new ArrayList&lt;Node&gt;();
          myList3 = new ArrayList&lt;Node&gt;();
          myList4 = new ArrayList&lt;Node&gt;();
  
          myList1.add(Node2);
          myList1.add(Node3);
          myList1.add(Node4);
  
          Node1 = new Node("One", myList1);
          Node2 = new Node("Two", myList2);
          Node3 = new Node("Three", myList3);
          Node4 = new Node("Four", myList4);
  
          List&lt;Node&gt; allNodesArray = nodeArray(Node1);
  
          for (int i = 0; i &lt; allNodesArray.size(); i++){
              System.out.println(allNodesArray.get(i).label);
          }
      }
  
      public static void main(String arg[]) {
          TestingArrays2 testArray = new TestingArrays2();
      }
  
      public List&lt;Node&gt; nodeArray(Node n){
          List&lt;Node&gt; tempList = new ArrayList&lt;Node&gt;();
  
          for (int i = 0; i &lt; n.children.size(); i++){
              tempList.add(n.children.get(i));
          }
  
      return tempList;
      }
  }
  </code></pre>