I do a condition with a value when it is null and when it is not null.
The time where this value is null I got the java.lang.NullPointerException.
How could I deal with this in order to dismiss this exception?
I need the condition when the value is null and when it is not.
You get a
NullPointerExceptionwhen you try to call a method using a variable that isnull. Simple example:So you should check if the variable is
nullbefore calling any method on it, for example:Note that a
NullPointerExceptionis usually easy to solve. Carefully look at the stack trace of the exception; it tells you exactly in which line of your code the exception happens. Check what could benullin that line of code, and check if you’re calling a method on something that might benull. Add a check (or prevent that the relevant thing can ever benullin another way).