我一直是个顽皮的男孩,我从 android 开发者网站的官方记事本应用程序中复制了一个方法,这是我的课:
package com.example.prva;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
public class ListView extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
fillData();
}
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = DatabaseManager.getAllData();
startManagingCursor(c);
String[] from = new String[] { DatabaseManager.TABLE_COLUMN_ONE };
int[] to = new int[] { R.id.text1 };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
}
}
当我尝试运行此 ListActivity 时,我收到此错误:
01-31 02:39:14.259: E/AndroidRuntime(1845): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.prva/com.example.prva.ListView}: java.lang.IllegalArgumentException: column '_id' does not exist
现在我明白了,因为它是真的,我的数据库中没有 _id 列(记事本应用程序数据库有它并使用它,但我有自己的数据库),我只是不明白我的 ListActivity 中提到的那个列在哪里班级?它是从哪里调用的,所以它给出了错误?