Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
原来的代码是:mSQLiteDatabase.query(table_name, new String[] {_title}, null, null, null, null, null);
修改后的代码为:mSQLiteDatabase.query(table_name, null, null, null, null, null, null);
这里的 new String[] {MyEvent._title} 是一个查询条件,数组里的内容是要查询表的列名,这里是限定你要查询的列。参数值为 null 表示查询所有列(包含有 “_id” 这一列) 。如里这样改也是可以 的:mSQLiteDatabase.query(table_name, new String[] {_id, _title}, null, null, null, null, null); 目的就是要你查询的结果中含有“_id” 这一列。
另外,关于sqlite数据库中的 "_id" 这一列,在sqlite数据库中是必须有的,而且列名还必须是 “_id” 一般为主键。而用以下代码在一个ListView中显示时,也需要用到 “_id” 这一列。
public void updataAdapter() {
if (mCursor != null && !mCursor.isClosed())
mCursor.close();
mCursor = m_MyDataBaseAdapter.fetchAllData();
mCursor.moveToFirst();
if (mCursor != null && mCursor.getCount() > 0) {
ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, mCursor, new String[] { _title }, new int[] { android.R.id.text1 });
listView.setAdapter(adapter);
}
}
总结
以上是生活随笔为你收集整理的Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: sqlite数据库的char,varch
- 下一篇: Android之状态栏通知Notific