What is a NullPointerException, and how do I fix it?

Ask a question
0

What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?

What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?

Coin iconoffer bounty
add comment

1 Answer

0

NullPointerException in java is a exception class. It happens when we try to access methods and fields of an object without constructing the object using new keyword.
So, always we need to check the object is null or not like,
if(obj != null){
//logic here
}
To prevent the program to terminate permanently, we need to use try-catch-finally concepts. Always put the erronus code within try block.

add comment

Your Answer