For an assignment, I had to create my own LinkedList class -- called BasicLinkedList -- that has many methods similar to LinkedList. I have to create a BasicListIterator that can iterate through the list, which contains the next(), previous(), hasNext(), and hasPrevious() methods. I'm having trouble with this, and keep getting NullPointerExceptions whenever I try to test it. Please let me know what I'm doing wrong!!
<CODE>
private class Node
{
public E data;
public Node next;
public Node prev;

}
private Node head;


private class MyListIterator implements BasicListIterator<E>
{
private Node position = head;

public E next()
{
if(!(hasNext()))
{
throw new NoSuchElementException();
}
else
{
E data = position.data;
position = position.next;
return data;
}
}

public E previous()
{
if(!(hasPrevious()))
{
throw new NoSuchElementException();
}
else
{
System.out.println(position);
E data = position.prev.data;
position = position.prev;
return data;
}
}

public boolean hasNext()
{
if(position == null)
{
return false;
}
else
{
return true;
}
}

public boolean hasPrevious()
{
if(position == head)
{
return false;
}
else
{
return true;
}
}



public void remove()
{
throw new UnsupportedOperationException();
}
}
</CODE>