Null Pointer Exception Causing Force Close While Trying To Run Multiple Threads
I'm trying to run a service in the background that sends texts messages of the location of the phone. In the service I use a Timer. The code that sends the messages runs correctly
Solution 1:
You need to replace
coordinates.equals(null)
with
coordinates == null
since the first one will never evaluate to true
, it will throw a NullPointerException()
every time coordinates
is null
.
Solution 2:
If your coordinates
is null then the very first condition oordinates.equals(null)
will result into NullPointerException
.
In addition, I have one more observation. The comparison coordinates == ""
is of no use as you are already using it in right way i.e. coordinates.equals("").
Change your if
from
if (coordinates.equals(null) || coordinates.equals("") ||
coordinates == null || coordinates == ""){
coordinates = "Could Not Receive Location";
}
to
if (coordinates == null || coordinates.equals("")){
coordinates = "Could Not Receive Location";
}
Post a Comment for "Null Pointer Exception Causing Force Close While Trying To Run Multiple Threads"