I'm having some trouble with a simple NullPointerException when trying to construct my own iterator for a HashTable, and I was wondering if this is the proper way to do it. I seem to get errors at the allEntries.add part of the code. Any help would be really appreciated!!
public class HashIterator implements Iterator<HashNode<K,V> > {
HashLinkedList<K,V> allEntries;
/**
* Constructor: make a linkedlist (HashLinkedList) 'allEntries' of all the entries in the hash table
*/
public HashIterator()
{
// ADD YOUR CODE BELOW HERE
for (int i=0; i<numBuckets; i++) {
HashLinkedList<K,V> currentBucket = buckets.get(i);
HashNode<K,V> curNode = currentBucket.getHead();
while (curNode != null) {
allEntries.add(curNode.getKey(), curNode.getValue());
curNode = curNode.getNext();
}
}
// ADD YOUR CODE ABOVE HERE
}