I am having a really frustrating issue:
I am trying to run an iterator, but it keeps on coming up with java.lang.NullPointerException at the hasNext class.
I am not quite sure where it might be trying to use a null value. I am assuming it is something to do with current. I added a if statement to check if current is null. But then it returns and unexpected value.
Help appreciated.
Code below:
private class Iterator implements Iterator
{
private Link<T> current;
public boolean hasNext () {
if(current.next == null)
return false;
return true;
}
public T next() throws OutOfBounds
{
if (this.hasNext())
{
T element = current.element;
current = current.next;
return element;
}
else
throw new OutOfBounds("No next element to call");
}
}
private class Link<T>
{
private T element;
private int priority;
private Link<T> next;
public Link(T t, int p, Link<T> n)
{
this.element = t;
this.priority = p;
this.next = n;
}
}
}