过去几天我有这个问题。我已经在这里阅读了所有类似的问题,并参考了许多教程,即使一切看起来都对我来说,我的程序仍然崩溃。
这是logcat:
08-02 15:13:41.876: D/ReminderProvider(1242): main oncreate called
08-02 15:13:41.984: I/dalvikvm(1242): threadid=3: reacting to signal 3
08-02 15:13:42.074: I/dalvikvm(1242): Wrote stack traces to '/data/anr/traces.txt'
08-02 15:13:42.234: D/ReminderListActivity(1242): onCreate
08-02 15:13:42.406: D/ReminderListActivity(1242): Displaying all the reminders in a list
08-02 15:13:42.474: I/dalvikvm(1242): threadid=3: reacting to signal 3
08-02 15:13:42.524: I/dalvikvm(1242): Wrote stack traces to '/data/anr/traces.txt'
08-02 15:13:42.804: D/gralloc_goldfish(1242): Emulator without GPU emulation detected.
08-02 15:13:43.234: D/ReminderProvider(1242): query
08-02 15:13:43.264: I/SqliteDatabaseCpp(1242): sqlite returned: error code = 1, msg = no such column: modified, db=/data/data/com.corsair.android.taskreminder/databases/reminders.db
08-02 15:13:43.274: W/dalvikvm(1242): threadid=11: thread exiting with uncaught exception (group=0x409c01f8)
08-02 15:13:43.374: E/AndroidRuntime(1242): FATAL EXCEPTION: AsyncTask #1
08-02 15:13:43.374: E/AndroidRuntime(1242): java.lang.RuntimeException: An error occured while executing doInBackground()
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.os.AsyncTask$3.done(AsyncTask.java:278)
08-02 15:13:43.374: E/AndroidRuntime(1242): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-02 15:13:43.374: E/AndroidRuntime(1242): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-02 15:13:43.374: E/AndroidRuntime(1242): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-02 15:13:43.374: E/AndroidRuntime(1242): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-02 15:13:43.374: E/AndroidRuntime(1242): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-02 15:13:43.374: E/AndroidRuntime(1242): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-02 15:13:43.374: E/AndroidRuntime(1242): at java.lang.Thread.run(Thread.java:856)
08-02 15:13:43.374: E/AndroidRuntime(1242): Caused by: android.database.sqlite.SQLiteException: no such column: modified: , while compiling: SELECT _id, title FROM reminders ORDER BY modified DESC
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:354)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:291)
08-02 15:13:43.374: E/AndroidRuntime(1242): at com.corsair.android.taskreminder.ReminderListProvider.query(ReminderListProvider.java:133)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.content.ContentProvider$Transport.query(ContentProvider.java:178)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.content.ContentResolver.query(ContentResolver.java:311)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.content.CursorLoader.loadInBackground(CursorLoader.java:56)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.content.CursorLoader.loadInBackground(CursorLoader.java:42)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:255)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:66)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:55)
08-02 15:13:43.374: E/AndroidRuntime(1242): at android.os.AsyncTask$2.call(AsyncTask.java:264)
08-02 15:13:43.374: E/AndroidRuntime(1242): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
因此,它声称我正在尝试访问不存在的列。这是我的ReminderListProvider查询方法中第133行的位,它表示发生了错误。第133行是queryBuilder.query调用:
// get the database and run the query
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor cursor = queryBuilder.query(db, projection, selection,
selectionArgs, null, null, orderby);
以下是我声明我的列并创建数据库的代码(我没有_id的声明,因为我的RemindersTableMetaData实现了BaseColumns):
public static final String REMINDER_TITLE = "title";
public static final String REMINDER_BODY = "body";
public static final String REMINDER_DATE_TIME = "reminder_date_time";
// script to create database
public static final String DATABASE_CREATE_SCHEMA = "create table "
+ DATABASE_TABLE_NAME + " (" + RemindersTableMetaData._ID
+ " integer primary key autoincrement, " + REMINDER_TITLE
+ " text not null, " + REMINDER_BODY + " text not null, "
+ REMINDER_DATE_TIME + " text not null" + ");";
以下是在查询调用之前调用的代码:
String[] uiBindFrom = { RemindersTableMetaData._ID,
RemindersTableMetaData.REMINDER_TITLE };
int[] uiBindTo = { R.layout.layout_reminder_list };
getLoaderManager().initLoader(REMINDER_LIST_LOADER, null, this);
adapter = new SimpleCursorAdapter(this, R.layout.layout_reminder_row,
null, uiBindFrom, uiBindTo, 0);
问题解决:只是为了向其他可能遇到此问题的人说清楚:发生了什么事我对方法的sortOrder参数如何感到困惑
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
被使用了。我以为这就像一个脚本命令。例如,您将传入LOW_TO_HIGH或其他内容,它会相应地对结果进行排序。是的,我有时候是个白痴。你实际想要传递的是一个列名,它将用于对游标中返回的行进行排序。无论如何,我传递了一个名为&#34; modified&#34;这不是一个声明的列名,因此程序崩溃了。我一直认为我设置数据库的方式有问题,而且一直以来我都忘记了这件看似微不足道的事情。这就是人生。感谢大家的帮助。
答案 0 :(得分:0)
尝试在设备/模拟器上卸载应用程序,可能是在没有修改过的列时创建数据库...
编辑:
// script to create database
public static final String DATABASE_CREATE_SCHEMA = "create table "
+ DATABASE_TABLE_NAME + " (" + RemindersTableMetaData._ID
+ " integer primary key autoincrement, " + REMINDER_TITLE
+ " text not null, " + REMINDER_BODY + " text not null, "
+ REMINDER_DATE_TIME + " text not null" + ");";
您从未在此处定义“已修改”列...
答案 1 :(得分:0)
只是为了向其他可能遇到此问题的人说清楚:发生了什么事我对方法的sortOrder
参数如何感到困惑
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
被使用了。我以为这就像一个脚本命令。例如,您将传入LOW_TO_HIGH或其他内容,它会相应地对结果进行排序。是的,我有时候是个白痴。你实际想要传递的是一个列名,它将用于对游标中返回的行进行排序。无论如何,我传入一个名为“modified”的字符串,它不是一个声明的列名,因此程序崩溃了。我一直认为我设置数据库的方式有问题,而且一直以来我都忘记了这件看似微不足道的事情。这就是人生。感谢大家的帮助。
答案 2 :(得分:0)
您传入的变量projection
,甚至您的相应表格,可能都没有modified
作为列。