我有一个自动完成功能,当我开始输入时,我会在数据库中显示两列的内容。
现在,我想对此进行过滤,并实现了以下方法:
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if (getFilterQueryProvider() != null) { return getFilterQueryProvider().runQuery(constraint); }
String filter="";
if(constraint==null) filter="";
else filter=constraint.toString();
Cursor cursor=db.getCursor(filter);
return cursor;
}
我的类中操作数据库的方法如下所示:
public Cursor getCursor(String prefix) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
String[] args = {prefix};
queryBuilder.setTables(TABLE_2);
String[] asColumnsToReturn = new String[] {"route","user_id"};
Cursor mCursor = queryBuilder.query(db,asColumnsToReturn,null, args, null, null,null);
int idcol = mCursor.getColumnIndexOrThrow(KEY_ROUTE);
int kwcol = mCursor.getColumnIndexOrThrow(KEY_USER_ID );
while(mCursor.moveToNext()) {
String id = mCursor.getString(idcol);
String kw = mCursor.getString(kwcol);
Log.d(id,kw);
}
return mCursor;
}
问题:为什么我的自动填充程序中没有显示任何内容?
这就是我的logcat的样子:
05-01 09:28:59.207: WARN/Filter(366): An exception occured during performFiltering()!
05-01 09:28:59.207: WARN/Filter(366): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x3114b8
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:178)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:190)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:55)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1220)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:316)
05-01 09:28:59.207: WARN/Filter(366): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:266)
05-01 09:28:59.207: WARN/Filter(366): at com.server.DBAdapter.getCursor(DBAdapter.java:199)
05-01 09:28:59.207: WARN/Filter(366): at com.server.Server8$ContactListCursorAdapter.runQueryOnBackgroundThread(Server8.java:185)
05-01 09:28:59.207: WARN/Filter(366): at android.widget.CursorFilter.performFiltering(CursorFilter.java:49)
05-01 09:28:59.207: WARN/Filter(366): at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
05-01 09:28:59.207: WARN/Filter(366): at
android.os.Handler.dispatchMessage(Handler.java:99)
05-01 09:28:59.207: WARN/Filter(366): at android.os.Looper.loop(Looper.java:123)
05-01 09:28:59.207: WARN/Filter(366): at
android.os.HandlerThread.run(HandlerThread.java:60)
答案 0 :(得分:0)
尝试在while循环之前调用moveToFirst()
mCursor.moveToFirst()
while(mCursor.moveToNext()) {
String id = mCursor.getString(idcol);
String kw = mCursor.getString(kwcol);
Log.d(id,kw);
}