1

我最近几天一直在处理这个问题。我在这里阅读了所有类似的问题,并查阅了许多教程,即使一切对我来说看起来都正确,我的程序仍然崩溃。

这是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 或其他内容,它会相应地对您的结果进行排序。是的,我有时是个白痴。您真正想要在这里传递的是一个列名,它将用于对游标中返回的行进行排序。无论如何,我传入了一个名为“modified”的字符串,它不是声明的列名,因此程序崩溃了。我一直认为我设置数据库的方式有问题,一直以来这都是我忘记自己做过的看似微不足道的事情。这就是生活。感谢大家的帮助。

4

3 回答 3

0

只是为了让其他可能遇到此问题的人清楚:发生的事情是我对sortOrder方法的论点感到困惑

@Override
public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {

被使用了。我认为这就像一个脚本命令。例如,您将传入 LOW_TO_HIGH 或其他内容,它会相应地对您的结果进行排序。是的,我有时是个白痴。您真正想要在这里传递的是一个列名,它将用于对游标中返回的行进行排序。无论如何,我传入了一个名为“modified”的字符串,它不是声明的列名,因此程序崩溃了。我一直认为我设置数据库的方式有问题,一直以来这都是我忘记自己做过的看似微不足道的事情。这就是生活。感谢大家的帮助。

于 2012-08-03T19:03:03.850 回答
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" + ");";

您永远不会在这里定义“修改”列...

于 2012-08-02T15:46:30.633 回答
0

您传入的变量projection,甚至您的相应表,大多可能没有modified作为列。

于 2017-08-31T06:27:33.593 回答