Getting A Nullpointerexception On A String Comparison
I get a null value from doseTimeString when I output with: Log.d('dosetimeString', '' + dosetimeString); But if I use an if condition on this line, it gives me a NullPointerEx
Solution 1:
The NullPointerException is occurring on this bit of your if statement:
dosetimeString.equals("null")
because you are calling a method on a null object, and as Roflcoptr says, if you actually need all those tests, you should make that line read:
if (dosetimeString == null || dosetimeString.equals("null") || dosetimeString.equals("")) {
However, if you just want to check if it is null, you only need the first condition.
if (dosetimeString == null) {
Solution 2:
That's because doestimeString is null. You can't access member functions on a null object!
Put the doestiemString==null before doestimeString.equals( "null" ) and you should be ok.
if (dosetimeString == null || dosetimeString.equals("null") || dosetimeString.equals("")){
}
Post a Comment for "Getting A Nullpointerexception On A String Comparison"