【发布时间】:2018-11-11 02:46:37
【问题描述】:
所以,我正在尝试编写一个程序,我可以在其中创建任务,在列表视图中显示它们的名称和日期,然后在列表视图中单击它们后简单地编辑它们
我在填充时遇到了一些问题。我需要为这个程序使用 SimpleCursorAdapter(作为我大学的作业)
这是我的 MainActivity 中的填充函数
private void populate(){
Cursor cursor = myDb.getAllRows();
String[] backDB = new String[] {DBAdapter.COLUMN_NAME, DBAdapter.COLUMN_DATE};
int[] toView = new int[] {R.id.textViewName, R.id.textViewDate};
SimpleCursorAdapter myCursor;
myCursor = new SimpleCursorAdapter(getBaseContext(), R.layout.row_layout, cursor, backDB,toView, 0);
ListView myList = (ListView) findViewById(R.id.listViewTasks);
myList.setAdapter(myCursor);
}
我认为它可能与 sql 数据库有关,尤其是 getAllRows 函数,因为在 logcat 中我可以看到该行存在问题:
myCursor = new SimpleCursorAdapter(getBaseContext(), R.layout.row_layout, cursor, backDB,toView, 0);
所以,这是我的 getAllRows 函数
public Cursor getAllRows() {
String query = "SELECT * FROM " + TABLE_NAME;
Cursor c = db.rawQuery(query, null);
c.moveToFirst();
return c;
}
我的程序崩溃了,顺便说一句。
【问题讨论】:
-
请从日志中添加堆栈跟踪。
标签: android-studio android-sqlite simplecursoradapter