我试图将数据调用到Listview,但应用程序终止。
数据库helper.java中的我有这个功能:
public List<Presentation> getAllPresentations() {
List<Presentation> presentations = new ArrayList<Presentation>();
String selectQuery = "SELECT * FROM " + TABLE_PRESENTATION;
Log.e(LOG, selectQuery);
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
if (c.moveToFirst()) {
do {
Presentation p = new Presentation();
p.setId(c.getInt((c.getColumnIndex(KEY_ID))));
p.setTitle(c.getString(c.getColumnIndex(KEY_TITLE)));
p.setDescription(c.getString(c.getColumnIndex(KEY_DESCRIPTION)));
p.setPatient_name(c.getString(c.getColumnIndex(KEY_PATIENT_NAME)));
presentations.add(p);
} while (c.moveToNext());
}
return presentations;
}
在xml文件(view_presentation)中我有一个带有id列表的ListView
在view_presentations.java中的我有这段代码:
public class view_presentations extends Activity
{
// Database Helper
DatabaseHelper db;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.view_presentation);
if (db.getPresentationsCount() != 0)
{
List<Presentation> list = db.getAllPresentations();
ListView l = (ListView)findViewById(R.id.list);
l.setAdapter(new ArrayAdapter<Presentation>(this, R.layout.view_presentation, list));
}
}
}
此时应显示包含所有演示文稿的列表,但应用程序将终止。有什么帮助吗?