1

ジェネリック型のオブジェクトをスタックにプッシュするような単純なことをできない理由がわかりません。これを理解するには、助けが必要だと判断しました。これは私が持っているものです:

private void preOrderTrav(BSTnode<K> node) {
            if(node != null){
            myStack.push(node); //Null pointer exception

            while(!myStack.isEmpty()){
                myStack.pop();
                node = node.getLeft();
                myStack.push(node.getRight());
                myStack.push(node.getLeft());

                }

            }
               }

これは私のコンストラクタから呼び出されています:

public BSTSortedListIterator(BSTnode<K> root) {
    preOrderTrav(root);
}

誰にもアイデアはありますか?ちなみに、このエラーが発生します:

Exception in thread "main" java.lang.NullPointerException
    at BSTSortedListIterator.preOrderTrav(BSTSortedListIterator.java:33)
    at BSTSortedListIterator.preOrderTrav(BSTSortedListIterator.java:31)
    at BSTSortedListIterator.<init>(BSTSortedListIterator.java:43)
    at BSTSortedList.iterator(BSTSortedList.java:130)
    at WebDictionary.main(WebDictionary.java:135)
4

4 に答える 4