I am doing this database operation in my application where I pull a certain column value to check if it exists. I have no problems executing the query and assigning the value to a string (I can even output this value in the Log). My problem arises when I try to check if my string is equal to null, ironically, I'm getting a NullPointer.
Here is my function:
public boolean isDone(String id){
boolean isDone = false;
String timeOut = new String();
timeOut = "A";
String query = "SELECT TimeOut FROM " + TABLE_ROUTE_TABLE + " WHERE _id = '" + id + "'";
Cursor cursor = mDB.rawQuery(query, null);
if(cursor.moveToFirst()){
timeOut = cursor.getString(cursor.getColumnIndex("TimeOut"));
Log.d("Hi", "timeOut = " + timeOut);
}
if(timeOut.equals(null)){
isDone = false;
}
else{
isDone = true;
}
return isDone;
}
I am getting the NPE at if(timeOut.equals(null)). I don't understand why I am getting an NPE when I put the string as part of a boolean condition when I am able to use it and display its value (which may sometimes be null).
I have a feeling I'm overlooking something basic. Any ideas?