문제

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. :/

도움이 되었습니까?

해결책

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)...

다른 팁

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top