java - Cursor throwing NullPointerException when calling moveToFirst() -


i've had crash report on play store looks this:

java.lang.nullpointerexception     @ android.database.sqlite.sqlitecursor.fillwindow(sqlitecursor.java:144)     @ android.database.sqlite.sqlitecursor.getcount(sqlitecursor.java:133)     @ android.database.abstractcursor.movetoposition(abstractcursor.java:196)     @ android.database.abstractcursor.movetofirst(abstractcursor.java:236)     @ com.myapp.myactivity(myactivity.java:283)     @ java.lang.thread.run(thread.java:856) 

at first thought cursor being null, can't because check if it's null before call movetofirst()

mcursor = getcursordata();  if (mcursor != null)     mcursor.movetofirst(); // line 283 

can tell me why crashing?

edit:

the code above pretty @ start of method it's inside. running inside onconfigurationchanged() can update tabs on activity new set cursor.

getcursordata() method inside sqliteopenhelper: reason i'm using rawquery due actual query using inner join. query fine it's worked perfect couple years without exception being thrown.

public cursor getcursordata(long userformid) {     sqlitedatabase db = getwritabledatabase();      return db.rawquery("select * table _id=?", new string[]{         string.valueof(id)     }); } 

i've changed code check getcount() before calling movetofirst(). i'm waiting on user having issue update new version see if has worked or not.

you should check count of data first, use this:

if(mcursor!=null && mcursor.getcount()>0 ){     mcursor.movetofirst(); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -