【发布时间】:2012-09-03 08:54:14
【问题描述】:
我正在尝试在数据库中查询。数据库不是在应用程序中创建的,我是在外部创建的,并且我正在使用 this tutorial 解释。但我有一个与列_id 相关的错误。 在 Class DatabaseHelper 中,我有以下代码:
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;
}
在Activity中,我写的代码是:
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”不存在
但是我创建的数据库有“_id”列:(我不能上传图片,所以这里是链接https://www.dropbox.com/s/9a2ol1acrnxmzob/sql-db-rusWjpg.png)
谢谢!
【问题讨论】:
-
尝试在没有
*但使用"_id, rusword, engword, kind"的情况下询问db ...如果没有_id列,您应该得到错误...