Domanda

Shouldn't this work just fine?

Cursor cursor = ourDatabase.rawQuery("SELECT * FROM " + DATABASE_TABLE + " WHERE " +     KEY_NAME + " = \'chaman\'",, null);

I don't know but I get an error when I try to call

cursor.getString(1);

it says CursorIndexOutofBoundsException

I've created my table using

db.execSQL("CREATE VIRTUAL TABLE " + DATABASE_TABLE
                + " USING fts3 (" + KEY_ID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME
                + " TEXT NOT NULL, " + KEY_ADDRESS
                + " TEXT NOT NULL, " + KEY_CONTACT + " TEXT NOT     NULL, "
                + KEY_BALANCE + " DOUBLE);");

& I'm sure chaman exists in my table as I can view it there in my database.

What's wrong? Please help me out. I'm stuck here for the last 1 hour. :/

È stato utile?

Soluzione

A CursorIndexOutOfBoundException means you either forgot to call moveToFirst() or you did call moveToFirst() but you didn't check its result (i.e. the Cursor is empty)...

Altri suggerimenti

You need make a call to moveToFirst

if(cursor.moveToFirst()) {  // returns false if no results
  // do stuff here
}

It would be a good idea to check the cursor count using cursor.getCount() and if the count > 0, then do moveToFirst, then you try to access the element using cursor.getString(1)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top