私はこのコンストラクターを持っています:
public class SentinelT<T> extends NodeT<T> {
//constructs an empty Sentinel linked to no other Nodes
public SentinelT() {
super(null, null, null);
this.prev = this;
this.next = this;
}
...
}
したがって、this.prevまたはthis.nextの値を変更しようとしたり、これらの値にブール演算子を使用しようとしたりすると、NullPointerExceptionが発生します。例えば:
public boolean isEmpty() {
return this.prev == this && this.next == this;
}
NullPointerExceptionをスローします。スーパーコンストラクターやnull値について何も理解していないような気がします...助けてくれてありがとう。
*編集:NodeTコンストラクターを追加し、例外をスローするインスタンス化を追加します
//NodeT class for a doubly linked list of T
public class NodeT<T> {
T data;
NodeT<T> prev;
NodeT<T> next;
//constructs a Node object
public NodeT(T data, NodeT<T> prev, NodeT<T> next) {
this.data = data;
this.prev = prev;
this.next = next;
}
* edit2:異なるクラス、stringHeaderがSentinelTで行われるクラスのフィールドであると想定しますstringHeader = new SentinelT();
public void testIsEmpty(Tester t) {
initData();
t.checkExpect(stringHeader.isEmpty(), true);
}