Why am I getting a stack overflow for myIt = new MyIterator<E>(start)?
<p>Here is my code....</p>

<pre><code> package calendar;

    import java.util.*;

    /**
     * This class represents a simple implementation of a sorted singly-linked list.
     * Elements added to the list are inserted in sorted order based on an specified
     * Comparator object.
     * &lt;br&gt;&lt;br&gt;
     * 
     * This class relies on two classes: MyIterator and MyListNode. We have implemented
     * the MyListNode class for you, but you are responsible for the implementation
     * of the MyIterator class.  Notice these are inner classes defined within the 
     * MySortedLinkedList class.  As a result they may access each other's fields even
     * if they are private.  You are required to use the MyListNode class to implement
     * the nodes of your linked list.
     * &lt;br&gt;&lt;br&gt;
     * 
     * Feel free to add any methods to the MySortedLinkedList class you consider are 
     * necessary to implement your project.  &lt;b&gt;However, keep in mind that there are two 
     * methods you are required to implement: an add method returning void (adds an element 
     * to the list keeping the list sorted) and a remove method returning void (removes 
     * any element(s) from the list that are equal to the parameter).&lt;/b&gt;  
     * 
     * The JUnit public tests provide an example of using the MySortedLinkedList class.
     * &lt;br&gt;&lt;br&gt;
     * 
     * You may not use the Java API LinkedList or ArrayList classes during the implementation
     * of the MySortedLinkedList class.
     *  
     * @author Dept of Computer Science, UMCP
     */

    public class MySortedLinkedList&lt;T&gt; implements Iterable&lt;T&gt; {
        private final Comparator&lt;T&gt; comparator; 
        MyListNode&lt;T&gt; head;
        public int counter = 0;
        /**
         * Creates an empty list that is associated with the specified comparator.
         * @param comparator
         */
        public MySortedLinkedList(Comparator&lt;T&gt; comparator) {
            //throw new UnsupportedOperationException("You must implement this method.");
            head = null;
            this.comparator = comparator;
        }

        /**
         * This class represents a linked list node. 
         * You should not modify this class. 
         * 
         * Because MyListNode is an inner class of MySortedLinkedList,
         * methods in MySortedLinkedList may access fields of MyListNode
         * directly even though they are private.
         * 
         * You may use the default constructor for MyListNode, which
         * initializes both val and next to null.
         * 
         * @param &lt;V&gt;
         */
        private class MyListNode&lt;V&gt; {
            private V val;
            private MyListNode&lt;V&gt; next;
        }



        /**
         * Inserts the specified element at the correct position in the sorted list.
         */
        public void add(T element) {
            MyListNode&lt;T&gt; n = new MyListNode&lt;T&gt;();
            n.val = element;
            n.next = head;
            head = n;

        }

        /**
         * Returns the element at the specified position in this list.
         */
        public T get(int index) {
            //throw new UnsupportedOperationException("You must implement this method.");
            int place = 1;
            MyListNode x = head;
            if(x==null){
                return null;
            }
            while(place&lt;index){
                x=x.next;
            }
            return (T) x.val;
        }

        /**
         * Removes any elements matching given element
         */
        public void remove(T v) { 
            //throw new UnsupportedOperationException("You must implement this method.");
            MyListNode prev = null, curr = head;
            while (curr != null) {
                if (curr.val.equals(v)) {
                    if (curr == head)
                        head = head.next;
                    else{
                        prev.next = curr.next;
                        prev = curr;
                        curr = curr.next;
                    }

                } else {
                    prev = curr;
                    curr = curr.next;
                }
            }
        } 

        public int size() {
            //throw new UnsupportedOperationException("You must implement this method.");
            MyListNode x = head;
            if(x==null){
                return 0;
            }
            while(x.next!= null){
                counter = counter + 1;
                x = x.next;
            }
            return counter;
        }

        public boolean isEmpty() {
            return head==null;
        }

        /**
         * Returns an iterator over the elements in this list (in proper sequence).  
         * @return iterator over the list
         */
        public Iterator&lt;T&gt; iterator() {
            MyIterator&lt;T&gt; something = new MyIterator&lt;T&gt;(head);
            return something;
        }

        /**
         * This class implements an iterator over the list.
         * You must implement this class. 
         * @param &lt;E&gt;
         */
        private class MyIterator&lt;E&gt; implements Iterator&lt;E&gt; {
            //private int counter1 = size();
            //@SuppressWarnings("unchecked")
            MyListNode&lt;E&gt; newHead = (MyListNode&lt;E&gt;) head;
            private Iterator&lt;E&gt; myIt;

            /**
             * Defines an iterator based on the start node provided.
             * @param start
             */
            private MyIterator(MyListNode&lt;E&gt; start) {
                //throw new UnsupportedOperationException("You must implement this method.");
                myIt = new MyIterator&lt;E&gt;(start);
            }

            /**
             * Returns true if there is another element available
             * @return true if there is another element and false otherwise
             */
            public boolean hasNext() {
                //throw new UnsupportedOperationException("You must implement this method.");
                if(head==null){
                    throw new NoSuchElementException();
                }else{
                    if(myIt.hasNext()||counter&gt;1){
                        return true;
                    }else{
                        return false;
                    }
                }
            }

            /**
             * Returns the next element
             * @return next element
             */
            public E next() {
                //throw new UnsupportedOperationException("You must implement this method.");
                if(hasNext()){
                    newHead = newHead.next;
                    return (E) newHead;
                }
                return null;
            }

            /**
             * Removes an element from the list.  You do not need to implement this method.
             */
            public void remove() {
                throw new UnsupportedOperationException("You do NOT need to implement this method");
            }
        }
    }
</code></pre>

<p>The error comes at <code>myIt = new MyIterator&lt;E&gt;(start);</code> in the private MyIterator constructor.  I have no idea why this is causing a stack overflow. Any ideas?  All the sections have comments saying what the goal is for each method. A few days ago I was just getting a NullPointerException, but I changed something and now get a StackOverflow with the error repeating on the line I stated.</p>

<p>The error comes from this test:</p>

<pre><code>public void testListEmpty() {
        MySortedLinkedList&lt;Activity&gt; myList = new MySortedLinkedList&lt;Activity&gt;(new ActivityComparator());
        Iterator&lt;Activity&gt; iterator = myList.iterator();
        assertTrue(iterator.hasNext() == false);
    }
</code></pre>
