Android的SimpleCursorAdapter没有这样的列ID [英] Android SimpleCursorAdapter No such column Id

查看:98
本文介绍了Android的SimpleCursorAdapter没有这样的列ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常令人沮丧的问题,本... 我有我想要填充从我SQLite数据库与信息,这似乎是最实际的解决方案列表视图。 在我调试它说,它造成的:抛出:IllegalArgumentException没有这样的列。 ID不存在

I'm having a really frustrating problem with this... I have a Listview that I want to populate with information from my SQLite database with and this seemed like the most practical solution. In my debugger it says it's caused by: IllegalArgumentException No such column. Id does not exist

这是java文件,我想用填充它:

This is the java file I'm trying to populate it with:

    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文件:

R.layout.list xml file:

<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"/>

public Cursor selectData() {

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

如果有人可以帮助我将是绝对感激:D

If anyone could help I will be absolutely grateful :D

推荐答案

您不包括 _id 在列列表中查询您做 getSpinnerData()

仅供参考,

您必须将触角延伸的CursorAdapter 这要求 _id 列。

You must be extending CursorAdapter which demand _id column.

_id 仅用于CursorAdapter的,以确定哪些列是ID。您可以覆盖这个行为的CursorAdapter或查询添加别名ID。

_id is used only in CursorAdapter to determine which column is id. You can override this behavior in CursorAdapter or add alias in query to id.

这篇关于Android的SimpleCursorAdapter没有这样的列ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆