我想在数据库中查询。数据库没有在应用程序中创建,我已经创建了外部,并且我正在使用this tutorial作为解释。但是我有一个与列_id相关的错误。 在类DatabaseHelper,我有以下代码:Android SQLite列_id错误,
public Cursor Search(Context context,String search){
SQLiteDatabase db= getReadableDatabase();
String cursorFactory = "SELECT * FROM words WHERE eng || ' ' || rus LIKE ?";
Cursor cursor = db.rawQuery(cursorFactory, new String[]{"%" + search + "%"});
return cursor;
}
活动中,我写的代码是:
public void search(View v){
text2search= searchText.getText().toString();
cursor= myDbHelper.Search(mContext, text2search);
adapter =new SimpleCursorAdapter(getBaseContext(),R.layout.list_item,
cursor,
new String[]{"rusword","engword","kind"},
new int[]{R.id.rusWord,R.id.engWord,R.id.knd});
wordsList.setAdapter(adapter);
}
而且我得到了_id相关的错误:(在logcat中)
09-03 14:12:38.018:E/AndroidRuntime(16581): java.lang.IllegalArgumentException异常:列 '_id' 不存在
致3210
但数据的基础上,我创造,它有“_id”列:(我不能上传图片,所以这里是链接https://www.dropbox.com/s/9a2ol1acrnxmzob/sql-db-rusWjpg.png)
谢谢!
试着问没有'*'的db,但是用'“_id,rusword,engword,kind”'......如果re不是'_id'列,你应该得到错误... – Selvin