Snažím se vytvořit nový BST od křižovatky 2 známých BSTs. Začínám NullPointerException v metodě intersect2 int on druhém případě, v řádku cur3.item.set_account_id (cur1.item.get_accountid () + cur2.item.get_accountid ());. Vím, že se dostanete k chybě při pokusu o dereference proměnné bez jeho inicializaci, ale myslím, že jsem to inicializaci? Nejsem si úplně jistý. Chtěl bych ocenit 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;
}
Zde je obraz problému: 













