空のリストに追加しているときに NPE が発生します。何が悪いのかわかりません。head=null と tail = null を初期化してから、head == null かどうかを確認しています。リストは空でなければならないので、head に追加します。これはリスト内の唯一のノードであるため、next で prev は null を指し、head=newnode および tail=newnode である必要があります。右??
public AddressList() {
head = null;
tail = null;
}
public void addEntry(String firstName, String lastName, String phoneNum, String email) {
EntryNode n = new EntryNode();
if (head == null) {
System.out.println("List is empty ");
n.setNext(null);
n.setPrev(null);
tail = n;
head = n;
}
else {
//add to the head
head.setPrev(n);
n.setNext(head);
head = n;
}
n.setFirstName(firstName);
n.setLastName(lastName);
n.setPhoneNum(phoneNum);
n.setEmail(email);
size++;
}