0
public Node searchData(String fullName)
{
    Node current = root;
    while(current.fullName != fullName)
    {
        if(fullName.compareTo(current.fullName) < current.fullName.compareTo(fullName))
        {
            current = current.leftChild;
        }
        else if(fullName.compareTo(current.fullName) > current.fullName.compareTo(fullName))
        {
            current = current.rightChild;
        }
        else
            current = null;
    }

    return current;
}

Whenever I enter a name into the program I receive a null pointer exception error. The program itself initializes a binary tree with a text-file and that already works but i'm not sure why it keeps crashing when I try to search for the node itself. I know the nodes already exist but can't figure out why it says that its null.

Teemo
  • 35
  • 7
  • A couple of thoughts here: 1) You should compare strings using `!current.fullName.equals(fullName)`; 2) Why do you want to compare like `a.compareTo(b) < b.compareTo(a)` - `a.compareTo(b) < 0` (or similar) would be more reasonable. – Andy Turner Mar 27 '16 at 20:03
  • That makes sense thank you – Teemo Mar 27 '16 at 20:05

0 Answers0