How to get the first element when going through a binary search tree with inorder?
<p>My try (gave me a NullPointerException):</p>

<pre><code>public Karte giveFirst(BinarySearchTree&lt;Karte&gt; t){
    if(t.getLeftTree() != null) {
        return giveFirst(t.getLeftTree());
    }else{
        return t.getContent();
    }
}
</code></pre>

<p>Complete Binary Search Tree Code:</p>

<pre><code>package  Model;


    private class BSTNode&lt;CT extends ComparableContent&lt;CT&gt;&gt; {

        private CT content;
        private BinarySearchTree&lt;CT&gt; left, right;

        public BSTNode(CT pContent) {

            this.content = pContent;
            left = new BinarySearchTree&lt;CT&gt;();
            right = new BinarySearchTree&lt;CT&gt;();
        }

    }

    private BSTNode&lt;ContentType&gt; node;

    public BinarySearchTree() {
        this.node = null;
    }

    public void insert(ContentType pContent) {
        if (pContent != null) {
            if (isEmpty()) {
                this.node = new BSTNode&lt;ContentType&gt;(pContent);
            } else if (pContent.isLess(this.node.content)) {
                this.node.left.insert(pContent);
            } else if(pContent.isGreater(this.node.content)) {
                this.node.right.insert(pContent);
            }
        }
    }

    public BinarySearchTree&lt;ContentType&gt; getLeftTree() {
        if (this.isEmpty()) {
            return null;
        } else {
            return this.node.left;
        }
    }

    public ContentType getContent() {
        if (this.isEmpty()) {
            return null;
        } else {
            return this.node.content;
        }
    }

    public BinarySearchTree&lt;ContentType&gt; getRightTree() {
        if (this.isEmpty()) {
            return null;
        } else {
            return this.node.right;
        }
    }

    public void remove(ContentType pContent) {
        if (isEmpty()) {
            return;
        }

        if (pContent.isLess(node.content)) {
            node.left.remove(pContent);
        } else if (pContent.isGreater(node.content)) {
            node.right.remove(pContent);
        } else {
            if (node.left.isEmpty()) {
                if (node.right.isEmpty()) {
                    node = null;
                } else {
                    node = getNodeOfRightSuccessor();
                }
            } else if (node.right.isEmpty()) {
                node = getNodeOfLeftSuccessor();
            } else {
                if (getNodeOfRightSuccessor().left.isEmpty()) {
                    node.content = getNodeOfRightSuccessor().content;
                    node.right = getNodeOfRightSuccessor().right;
                } else {
                    BinarySearchTree&lt;ContentType&gt; previous = node.right
                            .ancestorOfSmallRight();
                    BinarySearchTree&lt;ContentType&gt; smallest = previous.node.left;
                    this.node.content = smallest.node.content;
                    previous.remove(smallest.node.content);
                }
            }
        }
    }

    public ContentType search(ContentType pContent) {
        if (this.isEmpty() || pContent == null) {
            return null;
        } else {
            ContentType content = this.getContent();
            if (pContent.isLess(content)) {
                return this.getLeftTree().search(pContent);
            } else if (pContent.isGreater(content)) {
                return this.getRightTree().search(pContent);
            } else if (pContent.isEqual(content)) {
                return content;
            } else {
                return null;
            }
        }
    }
    private BinarySearchTree&lt;ContentType&gt; ancestorOfSmallRight() {
        if (getNodeOfLeftSuccessor().left.isEmpty()) {
            return this;
        } else {
            return node.left.ancestorOfSmallRight();
        }
    }

    private BSTNode&lt;ContentType&gt; getNodeOfLeftSuccessor() {
        return node.left.node;
    }

    private BSTNode&lt;ContentType&gt; getNodeOfRightSuccessor() {
        return node.right.node;
    }
}
</code></pre>

<p>How can I change/rewrite my code for it to work?</p>