Próbuję utworzyć nowy BST od skrzyżowania 2 znanych BSTS. Otrzymuję NullPointerException w metodzie intersect2 int on drugim przypadku, na linii cur3.item.set_account_id (cur1.item.get_accountid () + cur2.item.get_accountid ());. Wiem, że pojawia się błąd przy próbie dereference zmiennej bez inicjalizacji, ale myślę, że jestem inicjalizacji? Nie jestem do końca pewny. Byłbym wdzięczny za pomoc.
public static Bst<Customer> intersect(Bst<Customer> a, Bst<Customer> b){
return( intersect2(a.root, b.root));
}
public static Bst<Customer> intersect2(BTNode<Customer> cur1, BTNode<Customer> cur2){
Bst<Customer> result = new Bst<Customer>();
// 1. both empty -> true
if (cur1==null && cur2==null){
result=null;
}
// 2. both non-empty -> compare them
else if (cur1!=null && cur2!=null) {
BTNode<Customer> cur3 = new BTNode<Customer>();
cur3.item.set_account_id(cur1.item.get_accountid()+ cur2.item.get_accountid());
result.insert(cur3.item);
intersect2(cur1.left, cur2.left);
intersect2(cur1.right, cur2.right);
}
// 3. one empty, one not -> false
else if (cur1==null ||cur2==null){
BTNode<Customer> cur3 = new BTNode<Customer>();
cur3.item=null;
intersect2(cur1.left, cur2.left);
intersect2(cur1.right, cur2.right);
}
return result;
}
Oto obraz problemu: 













