我想使用SimpleCursorAdapter來填充ListView。但是,構造SimpleCursorAdapter讓我的編譯器引發了一個異常。最奇怪的是,在我的應用程序中,我幾乎使用了幾乎完全相同的結構來取得巨大成功。這就是我有問題:Android - SimpleCursorAdapter拋出異常
cursor = db.rawQuery("SELECT " + DatabaseHelper.KEY_AMOUNT
+ ", " + DatabaseHelper.KEY_DATE
+ " FROM " + DatabaseHelper.TABLE_HISTORY
+ " WHERE " + DatabaseHelper.KEY_ID
+ "=?",
new String[]{""+tenantId});
cursor.moveToFirst();
try {
tryAdapter = new SimpleCursorAdapter(
this,
R.layout.history_item,
cursor,
new String[] {DatabaseHelper.KEY_AMOUNT, DatabaseHelper.KEY_DATE},
new int[] {R.id.historyPaymentColumn, R.id.historyDateColumn});
} catch (Exception e) {
e.printStackTrace();
}
這裏就是我在應用程序中較早使用SimpleCursorAdapter(正常工作的那個)的實例:
cursor = db.rawQuery("SELECT _id, firstName, lastName, phone FROM phonebook", null);
adapter = new SimpleCursorAdapter(
this,
R.layout.phonebook_item,
cursor,
new String[]{"firstName", "lastName", "phone"},
new int[] {R.id.firstName, R.id.lastName, R.id.phone});
setListAdapter(adapter);
誰能告訴我是什麼這兩者之間的差異導致tryAdapter
失敗,但保持adapter
實例不變?
它爲什麼不起作用?什麼是例外?所以你最好在這裏發佈'Logcat'輸出。 – 2012-03-07 04:45:42