1

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

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

code with warning

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Who get me **negative rating** ,I don't know this problem . –  Apr 08 '15 at 06:34
  • 2
    This is only a warning, so you can probably ignore it. Also, above that, you have `catch (nullPointerException)`, Which is a [bad idea](http://stackoverflow.com/questions/2586290/is-catching-a-null-pointer-exception-a-code-smell). – Jonas Czech Apr 08 '15 at 06:35

1 Answers1

1

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();
    }
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350