Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ListView在我更改其表后不工作。安卓_Android_Sqlite_Android Listview - Fatal编程技术网

Android ListView在我更改其表后不工作。安卓

Android ListView在我更改其表后不工作。安卓,android,sqlite,android-listview,Android,Sqlite,Android Listview,我创建了一个列表视图,在屏幕上显示数据库的所有内容。我使用的代码是 private void fillData() { // Get all of the notes from the database and create the item list Cursor c = datasource.getAllActs(); startManagingCursor(c); String[] from = new String[] {DataBaseHelper.KEY_DA

我创建了一个列表视图,在屏幕上显示数据库的所有内容。我使用的代码是

 private void fillData() {
// Get all of the notes from the database and create the item list
   Cursor c = datasource.getAllActs();
    startManagingCursor(c);
    String[] from = new String[] {DataBaseHelper.KEY_DATE,  
    DataBaseHelper.KEY_STEPS,DataBaseHelper.KEY_CALs };
    int[] to = { R.id.code, R.id.Days, R.id.BMI };
    SimpleCursorAdapter notes = new SimpleCursorAdapter (this, R.layout.notes_row, c,  from, to);
   setListAdapter(notes);               
 }
这对下面的代码起了作用

 private void fillData() {
            // Get all of the notes from the database and create the item list
            Cursor c = datasource.getAllGoals();
            startManagingCursor(c);
            String[] from = new String[] {DataBaseHelper.KEY_GOAL, DataBaseHelper.KEY_Current,DataBaseHelper.KEY_Target };
            int[] to = { R.id.code, R.id.Days, R.id.BMI };
            SimpleCursorAdapter notes = new SimpleCursorAdapter (this, R.layout.notes_row, c, from, to);
            setListAdapter(notes);              
     }

我只是想知道这段代码是否有我可能遗漏的错误。如果您需要,我有logcat

我唯一能想到的是您的新
光标
没有名为
\u id
的列。确保光标

Cursor c = datasource.getAllActs();

有一个名为
\u id
的列,这是
SimpleCursorAdapter
类所要求的。

我唯一能想到的是,新的
光标
没有一个名为
\u id
的列。确保光标

Cursor c = datasource.getAllActs();

有一个名为
\u id
的列,这是
SimpleCorsOrAdapter
类所需要的。

忘记日志。。。从你的帖子中,我甚至不知道问题出在哪里。请发布logcat错误,这样如果Alex没有猜到的话,我们就可以看到问题出在哪里。忘记logcat。。。从你的帖子中,我甚至无法判断问题是什么。请发布logcat错误,这样如果Alex没有猜到,我们就可以看到问题是什么。可能是这样的,因为_ID不是gatAllActs()表的一部分;正在访问。另外,Alex是否有多个表具有相同的_id字段会导致任何问题。事实上,通常认为最好的做法是让所有表都包含一个自动递增的主键(即
\u id
)。每个表的列完全独立于任何其他表的列。除非您正在执行某种复杂的
连接
,否则应该不会有任何问题。我有点认为,在创建主键时,字段名需要是唯一的。因此,我可以有3个表,每个表都有相同的主键,名称为“\u id”。假设您有两个表,
table1
table2
,这两个表都有一个名为
\u id
的列。然后在SQLite语法中,您可以使用
table1.\u id
table2.\u id
引用这些列,因此您可以看到它们都是唯一的。唯一的限制是一个表不能包含两个名称相同的列(显然),这可能是因为_ID不是gatAllActs()表的一部分;正在访问。另外,Alex是否有多个表具有相同的_id字段会导致任何问题。事实上,通常认为最好的做法是让所有表都包含一个自动递增的主键(即
\u id
)。每个表的列完全独立于任何其他表的列。除非您正在执行某种复杂的
连接
,否则应该不会有任何问题。我有点认为,在创建主键时,字段名需要是唯一的。因此,我可以有3个表,每个表都有相同的主键,名称为“\u id”。假设您有两个表,
table1
table2
,这两个表都有一个名为
\u id
的列。然后在SQLite语法中,您可以使用
table1.\u id
table2.\u id
引用这些列,因此您可以看到它们都是唯一的。唯一的限制是一个表不能包含两个名称相同的列(显然)。