NoSuchElementExcpetion

Why is this code giving no such element exception at line 73 , whereas when I make the scanner object in function buildtree() as public static it runs fine.

No such element exception occurs when scanner tries to access an input but the input is not there. In your case you have used 2 scanners to access the inputs , instead of that you can make the scanner as static so that it can be accessed by both the functions .Static variable acts as global variable.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.