Java Error Correction
<p>I am trying to implement a tree using an array and I have all my code but I am receiving the following error, any ideas how to fix this? Also if you can find any other way to implement this without all the casting I'm doing that would be great. </p>

<pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.RangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at assign2Trees.ArrayTreeNode.&lt;init&gt;(ArrayTreeNode.java:17)
    at assign2Trees.ArrayTree.&lt;init&gt;(ArrayTree.java:21)
    at assign2Trees.ArrayTree.main(ArrayTree.java:110)


import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

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

    protected ArrayTreeNode&lt;E&gt;[] tree;
    protected E element;
    public static final int CAPACITY = 1024;
    protected List&lt;ArrayTreeNode&lt;E&gt;&gt; children;
    protected ArrayTreeNode&lt;E&gt; parent;
    protected ArrayTreeNode&lt;E&gt; root;


public ArrayTree(E e)
{
    tree = new ArrayTreeNode[CAPACITY];
    for(int i = 0; i&lt;CAPACITY; i++)
        tree[i] = new ArrayTreeNode&lt;E&gt;();   
    root = tree[0];
    root.setChildren(this.children);
    root.setElement(e);
    root.setParent(null);
}
public ArrayTree(E e, int size)
{ 
    tree = new ArrayTreeNode[size];
    for(int i = 0; i&lt;size; i++)
        tree[i] = new ArrayTreeNode&lt;E&gt;();
    root = tree[0];
    root.setElement(e);
    root.setChildren(this.children);
    root.setParent(null);

}
    public void delete(E node) throws RootNonDeletableException 
    {
        tree[Arrays.asList(tree).indexOf(node)] = null;
        parent(tree[Arrays.asList(tree).indexOf(node)]).addChild(tree[Arrays.asList(tree).indexOf(node)]); 
    }
    public boolean isEmpty() 
    {
        if (tree[0] == null)
            return true;
        else
            return false;
    }
    public Iterator&lt;E&gt; iterator() 
    {
        return new Iterator&lt;E&gt;()
        {
            private int index = 0;

            public boolean hasNext()
            {
                return index &lt; ArrayTree.this.size();
            }
            public E next() throws NoSuchElementException
            {
               if (!hasNext()) 
               {
                   return null;
               }
               return (E) ArrayTree.this.tree[index++];
            }
            public void remove() 
            {

            }   
        };
    }

    public E replace(E oldE, E newE) 
    {
        tree[Arrays.asList(tree).indexOf(oldE)] = (ArrayTreeNode&lt;E&gt;) newE; 
        return newE;
    }

    public E root() throws EmptyTreeException 
    {
        if (isEmpty())
            throw new EmptyTreeException();
        else 
            return (E) tree[0];
    }

    public int size() 
    {
        int count = 0;
        for (int i = 0; i &lt; tree.length; i++)
            count = count+1;
            return count;
    }   
    public Iterable&lt;E&gt; children(E node) 
    {
        return (Iterable&lt;E&gt;) children;
    }
    public ArrayTreeNode&lt;E&gt; parent(ArrayTreeNode&lt;E&gt; node)
    {
        return parent;
    }
    public E parent(E node) 
    {
        return (E) parent;
    }
    public static void main(String[] args)
    {
        ArrayTree&lt;String&gt; tree = new ArrayTree&lt;String&gt;("Eric"); 
        System.out.println(tree.size());
        tree.isEmpty();

    }

}





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

        public class ArrayTreeNode&lt;E&gt; {

            protected E element;
            protected List&lt;ArrayTreeNode&lt;E&gt;&gt; children;
            protected ArrayTreeNode&lt;E&gt; parent;

            public ArrayTreeNode()
            {
                children = new ArrayList&lt;ArrayTreeNode&lt;E&gt;&gt;();
                element = null;
                parent = children.get(0);
            }
            public ArrayTreeNode(E e)
            {
                children = new ArrayList&lt;ArrayTreeNode&lt;E&gt;&gt;();
                parent = children.get(0);
                element = e;
                this.setElement(e);
            }
            public void setElement(E e)
            {
                this.element = e;
            }
            public void setChildren(List&lt;ArrayTreeNode&lt;E&gt;&gt; kids)
            {
                this.children = kids;
            }
            public void addChild(ArrayTreeNode&lt;E&gt; child)
            {
                children.add(child);
            }
            public void deleteChildren()
            {
                this.children = new ArrayList&lt;ArrayTreeNode&lt;E&gt;&gt;();
            }
            public List&lt;ArrayTreeNode&lt;E&gt;&gt; getChildren()
            {
                return this.children;
            }
            public void setParent(ArrayTreeNode&lt;E&gt; e)
            {
                parent = e;
            }
        }
</code></pre>
