今天在使用Sqlite的cursor時出現以下錯誤訊息
05-02 02:54:56.928: E/AndroidRuntime(1660): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
再來看一下官方文件
public abstract int getColumnIndex (String columnName)
Since: API Level 1
Returns the zero-based index for the given column name, or -1 if the column doesn't exist. If you expect the column to exist use
getColumnIndexOrThrow(String)
instead, which will make the error more clear.if(cursor.getCount()>0) { while(cursor.moveToNext()) { String test=cursor.getString(cursor.getColumnIndex("customer_want")); Log.i("Tag","這是cursor取得的值:"+test.toString()); } }
沒有留言:
張貼留言