Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java BinarySearchTreeMap中的空指针_Java_Map_Insert_Nullpointerexception_Binary Search Tree - Fatal编程技术网

Java BinarySearchTreeMap中的空指针

Java BinarySearchTreeMap中的空指针,java,map,insert,nullpointerexception,binary-search-tree,Java,Map,Insert,Nullpointerexception,Binary Search Tree,我正在完成一个BinarySearchTreeMap类,它听起来就是这样的:它是一个用二进制搜索树实现的映射 我似乎得到了一个空指针异常,我就是无法控制它。我想在其他类似情况下也会发生这种情况。我得到了有问题的方法,我的逻辑似乎是正确的,因此,如果有人有任何关于为什么会有空指针的提示或提示,以及我将来如何防止这些,请让我知道 下面是我正在创建的方法-在外部节点插入条目: /** Auxiliary method for inserting an entry at an external

我正在完成一个BinarySearchTreeMap类,它听起来就是这样的:它是一个用二进制搜索树实现的映射

我似乎得到了一个空指针异常,我就是无法控制它。我想在其他类似情况下也会发生这种情况。我得到了有问题的方法,我的逻辑似乎是正确的,因此,如果有人有任何关于为什么会有空指针的提示或提示,以及我将来如何防止这些,请让我知道

下面是我正在创建的方法-在外部节点插入条目:

    /** Auxiliary method for inserting an entry at an external node.  Inserts e 
    *  at v, expanding v to be internal with empty external children, and then 
    *  returns e. */
    protected Entry<K,V> insertAtExternal(Position<Entry<K,V>> v, Entry<K,V> e) throws InvalidEntryException{
        if(isInternal(v)) throw new InvalidEntryException("You tried to insert an external at an  internal node!");
        replaceEntry(v,e); //replace the node at the given position
        insertLeft(v,null); //insert a dummy external node to the left of it
        insertRight(v,null); //insert a dummy external node to the right of it

        numEntries++; //since v is now internal, include it in the numEntries
        return e;

    }


    protected V replaceEntry(Position <Entry<K,V>> pos, Entry<K,V> ent) {
        ((BSTEntry<K,V>) ent).pos = pos;
        return replace(pos, ent).getValue();
    }
return语句是给我带来麻烦的行。 任何帮助都将不胜感激。 克劳迪娅

编辑: 以下是替换方法的实现方式:

replace(Position<E> v, E o) 
throws InvalidPositionException {
BTPosition<E> vv = checkPosition(v);
E temp = v.element();
vv.setElement(o);
return temp;
}

可以显示堆栈跟踪吗?replace方法是什么样子的?