user4501847
user4501847

Reputation:

Android - 'cursor.close()' may produce 'java.lang.nullpointerexception'?

I have bellow code which works just fine, but produces a warning:

method invocation 'cursor.close()' may produce 'java.lang.nullpointerexception'

code with warning

Upvotes: 1

Views: 1304

Answers (1)

Mureinik
Mureinik

Reputation: 312319

cursor_id may not be initialized, as, e.g., your try block checks. You need to add the same validation in the finally block:

} finally { 
    if (cursor_id != null) {
        cursor_id.close();
    }
}

Upvotes: 1

Related Questions