if(key == '1'){//insert at ->right.right
BinaryNode tempPointer = root;
while(tempPointer != null){
tempPointer = tempPointer.right;
}
BinaryNode newNode = new BinaryNode(x);
newNode.right = null;
newNode.left = null;
size++;
lastNode = newNode;
newNode.parent = tempPointer;
tempPointer.right = newNode;
}
它一直说 termPointer
只能在这个位置为空。虽然我不明白为什么。
这也失败了:
newNode.parent = tempPointer.parent; //'tempPointer can only be null here'
tempPointer = newNode;
最佳答案
您的 while 循环只会在 tempPointer 为 null
时结束。在循环之后,您没有将 tempPointer
设置为任何其他值,因此它将保持 null
直到函数结束。
关于java - Java 中的 'Null pointer access' 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5529131/