使用 SimpleCursorAdapter 时java.lang.IllegalArgumentException: column '_id' does not exist问题
解决思路,没有'_id',那就给它指定一个'_id'就可以了,用sql的selsect as 语句完美解决,注意此处是'_id',而不是'id'
首先,要有一个类似id列可以指定为'_id'的,我这里的dot表中是id列。
然后,自己看吧
Cursor cursor = DataSupport.findBySQL("select id as _id, submittime, address from dot order by submittime desc");
Logg.e("TAG", cursor.getColumnName(1).toString());
String[] from = {"submittime", "address"};//列名与控件id一一对应
int[] to = {R.id.fruit_time, R.id.fruit_name};
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.item_dot, cursor, from, to, CursorAdapter.FLAG_AUTO_REQUERY);
setListAdapter(mAdapter);最重要的是第一行的as
本文介绍了解决在使用SimpleCursorAdapter时遇到的'_id'不存在的问题的方法。通过SQL的SELECT AS语句,将现有的列重命名为'_id',从而避免了IllegalArgumentException异常。
3398

被折叠的 条评论
为什么被折叠?



