I always use this method, so far it never crash yet Cursor c; ... //check if there is any cursor if (c.getCount() > 0) { //move to the first cursor c.moveToFirst(); do { //retrieve the cursor data here ..... } while (cur.moveToNext()); //check if next cursor is still valid }
On Jun 17, 4:25 pm, Justin Anderson <janderson....@gmail.com> wrote: > Did this help? > > ---------------------------------------------------------------------- > There are only 10 types of people in the world... > Those who know binary and those who don't. > ---------------------------------------------------------------------- > > On Wed, Jun 16, 2010 at 2:38 PM, Justin Anderson > <janderson....@gmail.com>wrote: > > > Also, I use different methods in my while loop: > > > Cursor dbCursor; > > ... > > dbCursor.moveToFirst(); > > while (!dbCursor.isAfterLast()) > > { > > //do stuff > > dbCursor.moveToNext(); > > > } > > > ---------------------------------------------------------------------- > > There are only 10 types of people in the world... > > Those who know binary and those who don't. > > ---------------------------------------------------------------------- > > > On Wed, Jun 16, 2010 at 2:07 PM, Mikey <frak....@gmail.com> wrote: > > >> Mostly desperation - I will give your idea a try though - thanks! > > >> Mikey > > >> On 16 Jun 2010, at 21:04, Justin Anderson wrote: > > >> I'm not entirely sure, but I noticed my code is a little different than > >> yours... > > >> Before I loop over the rows in the cursor I call moveToFirst(). So, with > >> your code that would be c.moveToFirst() right before the while loop. I seem > >> to remember having some weird issues with the Cursor class but haven't had > >> any since I've made this change. > > >> Also, why are you setting c to null? There really is no point in doing > >> that as the garbage collector will get called on you move out of c's > >> scope... which happens as soon as you leave the try block. > > >> Thanks, > >> Justin > > >> ---------------------------------------------------------------------- > >> There are only 10 types of people in the world... > >> Those who know binary and those who don't. > >> ---------------------------------------------------------------------- > > >> On Wed, Jun 16, 2010 at 12:13 PM, Mikey <frak....@gmail.com> wrote: > > >>> Hi, > > >>> I am using a a Sqlite database in my application, but I am having a > >>> problem with it crashing (seemingly) randomly with the exception in > >>> Cursor. > >>> (I have been unable to recreate the error to give you the exact exception > >>> but it is something like the cursor being in an invalid state. > > >>> I am using the cursor as follows: > > >>> public ArrayList<String> fetchPermanent() { > >>> ArrayList<String> rows = new ArrayList<String>(); > >>> try { > >>> Cursor c = mDb.query(USERS, new String[] {SCREEN_NAME}, CONSTANT + > >>> "='C'", null, null, null, null); > >>> if (c != null && c.getCount() > 0) { > >>> while (!c.isLast()) { > >>> c.moveToNext(); > >>> rows.add(c.getString(0)); > >>> } > >>> c.close(); > >>> c = null; > >>> } > >>> } > >>> catch (Exception e) { > >>> Log.e("DBERR", e.getMessage()); > >>> } > >>> return rows; > >>> } > > >>> Does anyone here have any idea what it is I am doing wrong? > > >>> Mikey > > >>> -- > >>> You received this message because you are subscribed to the Google > >>> Groups "Android Beginners" group. > > >>> NEW! Try asking and tagging your question on Stack Overflow at > >>>http://stackoverflow.com/questions/tagged/android > > >>> To unsubscribe from this group, send email to > >>> android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > >>> For more options, visit this group at > >>>http://groups.google.com/group/android-beginners?hl=en > > >> -- > >> You received this message because you are subscribed to the Google > >> Groups "Android Beginners" group. > > >> NEW! Try asking and tagging your question on Stack Overflow at > >>http://stackoverflow.com/questions/tagged/android > > >> To unsubscribe from this group, send email to > >> android-beginners+unsubscr...@googlegroups.com > >> For more options, visit this group at > >>http://groups.google.com/group/android-beginners?hl=en > > >> -- > >> You received this message because you are subscribed to the Google > >> Groups "Android Beginners" group. > > >> NEW! Try asking and tagging your question on Stack Overflow at > >>http://stackoverflow.com/questions/tagged/android > > >> To unsubscribe from this group, send email to > >> android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > >> For more options, visit this group at > >>http://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en