simplecursoradapter不工作

Fla*_*icc 2 sqlite android listview listadapter simplecursoradapter

我正在使用数据库,从中获取光标,然后使用simplecursoradapter填充列表视图.我似乎无法弄清楚为什么应用程序在创建一个新的simplecursoradapter时崩溃了.我的光标包含在单个对象中.我通过这个类中的数据变量引用它.

String[] columns = new String[] {"item", "quantity", "days"};
int[] to = new int[] { R.id.nametext, R.id.quantitytext, R.id.dayslefttext};
SimpleCursorAdapter sCA = new SimpleCursorAdapter(this, R.layout.itemrow, data.listCursor, columns, to);
listView1.setAdapter(sCA);
Run Code Online (Sandbox Code Playgroud)

simplecursoradapter对构造函数中传递给它的信息做了什么?格式错误的参数之一是什么?这是我用来查看是否有效的每一行的简单xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content">
  <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Loading Screen" 
    android:id="@+id/nametext"/>
  <TextView
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Loading Screen" 
    android:id="@+id/quantitytext"/>
  <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Loading Screen" 
    android:id="@+id/dayslefttext"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我加载游标的方法:

listCursor = myDataBase.query(ITEMS_TABLE, null, "location" +" = ?", new String[]{IN_SPECIAL_LIST}, null, null, "item");
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚问题是什么.我通过一些调试来运行它,当II创建新的simplecursoradapter时会出现问题.

Sel*_*vin 5

myDataBase.query(ITEMS_TABLE, null, ...
Run Code Online (Sandbox Code Playgroud)

这个null是你的问题,这意味着查询将使用,SELECT *_id你的表中没有列,所以你应该使用

new String[] {"YOURID AS _id", "item", "quantity", "days"}
Run Code Online (Sandbox Code Playgroud)

SimpleCursorAdapter需要_id列

YOURID可以是ROWID(ROWID为_id),也可以是数据库中的任何int或long ID