Java LinkedTree Help
<p>I am trying to implement a linked tree but I am getting a nullpointer exception when I run it. Can you help me fix it up. </p>

<pre>
    Exception in thread "main" java.lang.NullPointerException
        at assign2Trees.LinkedTree.size(LinkedTree.java:16)
        at assign2Trees.LinkedTree.main(LinkedTree.java:80)
</pre>

<pre><code>import java.util.Iterator;
import java.util.NoSuchElementException;

public class LinkedTree&lt;E&gt; implements Tree&lt;E&gt;{

    private Node&lt;E&gt; root;

    public LinkedTree()
    {
        super();
    }
    public int size()
    {
        return root.getChildren().size() + 1;
    }   
    public boolean isEmpty() 
    {
        if(root == null)
            return true;
        else
            return false;
    }
    public Iterator&lt;E&gt; iterator() 
    {
        return new Iterator&lt;E&gt;()
        {
            private int i = 0;

            public boolean hasNext()
            {
                return i &lt; LinkedTree.this.size();
            }
            public E next() throws NoSuchElementException
            {
               if (!hasNext()) 
               {
                   return null;
               }
               return (E) LinkedTree.this.root.getChildren().get(i++);
            }
            public void remove() 
            {

            }
        };
    }
    public E replace(E oldE, E newE) 
    {
        int i = root.getChildren().indexOf(oldE);
        root.getChildren().add(i, (Node&lt;E&gt;) newE);  
        return newE;
    }
    public E root() throws EmptyTreeException 
    {
        if (isEmpty())
            throw new EmptyTreeException ();
        return this.root();
    }
    public E parent(E node) 
    {
        return (E) ((Node&lt;E&gt;) root.getChildren()).getParent((root.getChildren().get(root.getChildren().indexOf(node))));    
    }
    public Iterable&lt;E&gt; children(E node) 
    {
        return (Iterable&lt;E&gt;) root.getChildren().listIterator();
    }
    public void delete(E node) throws RootNonDeletableException 
    {
        if (node == null)
            throw new RootNonDeletableException();
        else
            root.getChildren().remove(root.getChildren().indexOf(node));
    }

    public static void main(String[] args)
    {
        LinkedTree&lt;Node&lt;String&gt;&gt; tree = new LinkedTree&lt;Node&lt;String&gt;&gt;();
        System.out.println(tree.size());

    }


}


import java.util.ArrayList;
import java.util.List;

public class Node&lt;E&gt;{

    protected E contents;
    protected List&lt;Node&lt;E&gt;&gt; children;
    protected Node&lt;E&gt; parent;

    public Node()
    {
        super();
    }
    public Node(E contents)
    {
        this.setContents(contents);
    }
    public List&lt;Node&lt;E&gt;&gt; getChildren()
    {
        if(this.children == null)
        {
            return new ArrayList&lt;Node&lt;E&gt;&gt;();
        }
        return this.children;
    }
    public void setChildren(List&lt;Node&lt;E&gt;&gt; children)
    {
        this.children = children;
    }
    public void addChild(Node&lt;E&gt; child)
    {
        if (children == null)
        {
            children = new ArrayList&lt;Node&lt;E&gt;&gt;();
        }
        children.add(child);
    }
    public E getContents()
    {
        return this.contents;
    }
    public void setContents(E contents)
    {
        this.contents = contents;
    }
    public Node&lt;E&gt; getParent(Node&lt;E&gt; node)
    {
        return node.parent;
    }
    public void setParent(Node&lt;E&gt; parent, Node&lt;E&gt; child)
    {
        child.parent = parent;
    }
}
</code></pre>
