Android SimpleCursorAdapter没有这样的列ID

pop*_*pop 3 android illegalargumentexception simplecursoradapter

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

IllegalArgumentException没有这样的列.Id不存在

这是我试图填充它的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);
Run Code Online (Sandbox Code Playgroud)

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);
}
Run Code Online (Sandbox Code Playgroud)

Par*_*ani 5

您没有_id在列列表中包含您在getSpinnerData()中执行的查询.

仅供参考,

您必须扩展需要列的CursorAdapter_id.

_id仅在CursorAdapter中用于确定哪个列是id.您可以在CursorAdapter中覆盖此行为,或在查询中将别名添加到id.