こんにちは、SQL データベースを使用して Android アプリを作成しようとしています。結果をリストビューにリストしたいのですが、うまくいかないようです。これまでのところ、エラーが発生しています。
java.lang.IllegalArgumentException: 列 '_id' が存在しません
SimpleCursorAdapter adp;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db.open();
// from array: keeps the names of the Cursor columns.
String[] from = {"CURSOR_FIELD1","CURSOR_FIELD2"};
// to array: keeps the ids of the fields in your list item layout
int[] to = {R.id.itemLayoutfield1, R.id.itemLayoutfield2};
// sets the basic layout of the ListActivity (the layout must contain a ListView element with the id called 'list').
setContentView(R.layout.view_data_layout);
// gets de cursor with the rows
c = db.getAllCourses();
adp = new SimpleCursorAdapter(this, R.layout.row, c, from, to);
setListAdapter(adp);
ListView listView = getListView();
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
displayAllCourses(c);
db.close();
}
});
そして私が持っている私のdbadapter
public Cursor getAllCourses() {
return db.query(DATABASE_TABLE, new String[] { ID, Time_Amount,
Seed_Acre, MM_Settings, Acre_amount, Speed_Type, Acre_String, Seed_Type, Hill_Name }, null, null,
null, null, null, null);
}
public Cursor getCourse(long rowId) throws SQLException {
Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] { ID,
Time_Amount, Seed_Acre, MM_Settings, Acre_amount, Speed_Type, Acre_String, Seed_Type, Hill_Name },
ID + "=" + rowId, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}