Hi Everyone you might have faced many troubles while writing code and you got that error many a times while learning!
Follow the steps below, I'm sure you're gonna make it! 💪👩💻
Some programming languages may not require indentation to work properly, but it is always recommended to indent your code properly while finding the errors in the code you can understand better, what's happening with good organisation of code.
You can easily find the missing parentheses, if any causing errors.
Some times we may have declared the same variable name twice or even better we might have missed the scope of the variable we are using. So it's better to have a look at variables.
Also name the variables descriptively, that it's easy to understand what it does and makes our process of finding bugs easy-peasy 🙂
It's really important to test our program with different inputs to understand the program flow better and to find out what's that tiny case that's causing the program to break. If you're writing test cases don't forget to write test cases with all the possible inputs to find the case where our program simply doesn't work!
By this time you may got some idea by following the previous steps, now log or print the values of variables and check whether the value of variable is as expected or not.
I bet by this step you'll have probably figured out what that tiny little bug is.
This is where most of the programmers fall prey and don't forget to initialise the variables ever.
This is quite critical and causes NullPointerException.
If there is an error thrown, focus on the stack trace of the error where it shows the methods involved in causing the error and then go and squash the error.
Create break points wherever you doubt and then run the program and check it out to find the bug.
I'm sure by this step you'll successfully resolve your bug or error.
As the code complexity grows it will become too tough to find mistakes and resolve them, so do it step by step while building code.