I have to write a hashtable that uses chaining in the array index to store multiple values in the same place place rather than linear probing.
However my array of linked lists seems to instance full of nulls in this test but I get a NullPointerException
when I try to call linked list methods. Neither me nor my professor can seem to figure out why.
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import Hash.*;
import LinkedList.*;
public class Main {
public static void main(String[] args) {
LList<Integer>[] testArray = (LList<Integer>[]) new LList<?>[5];
for(int i=0;i<5;i++)
System.out.println(testArray[i]);
System.out.println(testArray[0]);
System.out.println(testArray[0].size());
testArray[0].add(40);
}
}
Then the Linked List class package LinkedList;
public class LList<T> implements I_LList<T> {
protected int numElements;
protected boolean found;
protected LLNode<T> current;
protected LLNode<T> previous;
protected LLNode<T> list;
public LList(){
list = null;
current = null;
numElements = 0;
}
public void add(T element){
System.out.println("LList add()");
LLNode<T> newNode = new LLNode<T>(element);
newNode.setLink(list);
list = newNode;
numElements++;
}