Én próbálunk létrehozni egy új BST metszéspontjában 2 ismert BSTs. Kapok egy NullPointerException a intersect2 eljárás int neki második esetben a vonal cur3.item.set_account_id (cur1.item.get_accountid () + cur2.item.get_accountid ());. Tudom, hogy kap a hiba, amikor megpróbálja dereference változó nélkül inicializáló de azt hiszem, én inicializálnunk? Nem vagyok benne biztos. Örülnék segítséget.
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;
}
Itt látható a képen a problémát: 













