gpt4 book ai didi

Android SimpleCursorAdapter 没有这样的列 Id

转载 作者:太空宇宙 更新时间:2023-11-03 12:40:59 24 4
gpt4 key购买 nike

我有一个 ListView ,我想用我的 SQLite 数据库中的信息填充它,这似乎是最实用的解决方案。在我的调试器中,它说它是由以下原因引起的:

IllegalArgumentException No such column. Id does not exist

这是我试图填充它的 java 文件:

    data        = new MyData(this);
ListView lv = (ListView) findViewById(R.id.list);

ListAdapter adapter = new SimpleCursorAdapter(
this,
R.layout.list,
data.selectData(),
new String[] {
"name",
"title"
},
new int[] {
R.id.name,
R.id.title
}
);
lv.setAdapter(adapter);

R.layout.list xml文件:

<LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="8dip"/>
<TextView android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

</LinearLayout>

public Cursor selectData() {

return db.query("tbl_mydata", new String[] {"name", "abb" }, null, null, null, null, null);
}

最佳答案

对于您在 getSpinnerData() 中执行的查询,您没有将 _id 包括在列列表中。

仅供引用,

您必须扩展 CursorAdapter这需要 _id 列。

_id 仅在 CursorAdapter 中用于判断哪一列是 id。您可以在 CursorAdapter 中覆盖此行为或在查询中向 id 添加别名。

关于Android SimpleCursorAdapter 没有这样的列 Id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8090425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com