NPE in own realization of LinkedList (Java) : <p>I'm a beginner in programming and I need to write some kind of own LinkedList, but only with <code>add(E element)</code> method and with Iterator's <code>hasNext()</code> and <code>next()</code>. Here is my code:</p>

<pre><code>  public class LinkedArray&lt;E&gt; implements Iterator&lt;E&gt; {

        private int size = 0;

        private int current = 0;

        private Node&lt;E&gt; first;

        private Node&lt;E&gt; last;

        private Objects[] objects = new Objects[10];

        public void add(E value) {
            Node&lt;E&gt; element = new Node&lt;E&gt;(last, value, null);
            if (last != null) {
                element.next = element;
            } else {
                first = element;
            }
            last = element;
            size++;
        }

        @Override
        public boolean hasNext() {
            boolean result = false;
            try {
                if (objects[current + 1] != null) {
                    result = true;
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                result = false;
            }
            return result;
        }

        @Override
        public E next() {
            E result;
            try {
                current++;
                result = (get(current - 1));
            } catch (ArrayIndexOutOfBoundsException a) {
                throw new NoSuchElementException("No more elements in list.");
            }
            return result;
        }

   public E get(int position) throws NullPointerException {
        Object result;
    if (this.objects[position] != null) {
        result = this.objects[position];
    } else {
        throw new NullPointerException("Position is empty.");
    }
    return (E) result;
}


        private class Node&lt;E&gt; {

            private E element;

            private Node&lt;E&gt; next;

            private Node&lt;E&gt; prev;

            Node(Node&lt;E&gt; prev, E element, Node&lt;E&gt; next) {
                this.element = element;
                this.next = next;
                this.prev = prev;
            }
        }
    }
</code></pre>

<p>But when I started to test add(E value)...</p>

<pre><code>@Test
    public void test() {
        LinkedArray&lt;String&gt; arr = new LinkedArray&lt;&gt;();
        String string = "Test";

        arr.add(string);
        String result = arr.next();

        assertThat(result, is("Test"));
    }
</code></pre>

<p>...I only get an error. What the problem is, why am I getting it wrong?</p>
