I'm getting this error when I run my code to see if a Binary Tree is full: The error I'm getting from my code is:
Exception in thread "main" java.lang.NullPointerException: **Cannot invoke
"BinaryTree$Node.isAFullTree()" because "this.right" is null**
at BinaryTree$Node.isAFullTree(BinaryTree.java:97)
at BinaryTree$Node.isAFullTree(BinaryTree.java:97)
at BinaryTree$Node.isAFullTree(BinaryTree.java:97)
at BinaryTree.isAFullTree(BinaryTree.java:209)
at Main.main(Main.java:30)
public boolean isAFullTree ()
if(left == null && right != null
{
return false;
}
if(left != null && right == null
{
return false;
}
return true && right.isAFullTree() && left.isAFullTree(); // This line throws the exception
}
}