Check you table if it has any records. android.database. > > CursorIndexOutOfBoundsException: Index -1 requested, > with a size of 1
On Sat, Nov 13, 2010 at 2:19 AM, Miiohau <[email protected]> wrote: > I am getting a Weird cursorIndexOutOfBoundsException > The logcat: > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): FATAL EXCEPTION: main > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): > java.lang.RuntimeException: Unable to start activity > ComponentInfo{com.gremlingames.rimblade/ > com.gremlingames.rimblade.LevelSelectionActivity}: > android.database.CursorIndexOutOfBoundsException: Index -1 requested, > with a size of 1 > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > 2663) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: > 2679) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.app.ActivityThread.access$2300(ActivityThread.java:125) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.os.Handler.dispatchMessage(Handler.java:99) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.os.Looper.loop(Looper.java:123) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.app.ActivityThread.main(ActivityThread.java:4627) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > java.lang.reflect.Method.invokeNative(Native Method) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > java.lang.reflect.Method.invoke(Method.java:521) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > com.android.internal.os.ZygoteInit > $MethodAndArgsCaller.run(ZygoteInit.java:868) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > dalvik.system.NativeStart.main(Native Method) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): Caused by: > android.database.CursorIndexOutOfBoundsException: Index -1 requested, > with a size of 1 > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.database.AbstractCursor.checkPosition(AbstractCursor.java:580) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > > android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java: > 214) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java: > 84) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > > com.gremlingames.rimblade.LevelSelectionActivity.onCreate(LevelSelectionActivity.java: > 52) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: > 1047) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): at > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > 2627) > 11-12 13:17:01.545: ERROR/AndroidRuntime(329): ... 11 more > > The relevant code snippet: > RimbladeDatabaseOpenHelper dataBaseOpener = new > RimbladeDatabaseOpenHelper( > (Context) getApplication()); > SQLiteDatabase rimbladeDatabase = > dataBaseOpener.getReadableDatabase(); > Cursor levelCursor = rimbladeDatabase.rawQuery("SELECT " > + RimbladeDatabaseOpenHelper.LEVEL_COL_NAME > + " as _id, " > + RimbladeDatabaseOpenHelper.SCORE_COL_NAME > + " FROM " > + > RimbladeDatabaseOpenHelper.SCORE_TABLE_NAME, null); > > int totalScore = 0; > int scoreIndex = levelCursor > > .getColumnIndex(RimbladeDatabaseOpenHelper.SCORE_COL_NAME); > while (!levelCursor.isAfterLast()) { > totalScore += levelCursor.getInt(scoreIndex); > } > The RimbladeDatabaseOpenHelper: > public class RimbladeDatabaseOpenHelper extends SQLiteOpenHelper { > > private static final int DATABASE_VERSION = 1; > public static final String SCORE_TABLE_NAME = "scores"; > public static final String LEVEL_COL_NAME = "level"; > public static final String SCORE_COL_NAME = "score"; > private static final String SCORE_TABLE_CREATE = > "CREATE TABLE " + SCORE_TABLE_NAME + " (" + > LEVEL_COL_NAME + " TEXT NOT NULL, " + > SCORE_COL_NAME + " INT NOT NULL);"; > > > > public RimbladeDatabaseOpenHelper(Context context) { > super(context, "rimblade", null, DATABASE_VERSION); > } > > public void onCreate(SQLiteDatabase db) { > db.execSQL(SCORE_TABLE_CREATE); > android.content.ContentValues values = new > android.content.ContentValues(); > values.put(LEVEL_COL_NAME, "start"); > values.put(SCORE_COL_NAME, 0); > db.insert(SCORE_TABLE_NAME, SCORE_COL_NAME, values); > } > > @Override > public void onUpgrade(SQLiteDatabase db, int oldVersion, int > newVersion) { > > } > > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Kumar Bibek http://techdroid.kbeanie.com http://www.kbeanie.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

