gpt4 book ai didi

android - Android SQL崩溃-没有这样的专栏

转载 作者:行者123 更新时间:2023-12-03 16:15:29 25 4
gpt4 key购买 nike

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

这是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”的字符串,该字符串不是声明的列名,因此程序崩溃了。我一直以为我设置数据库的方式有问题,而且一直以来,这都是我忘记做的看似微不足道的事情。这就是人生。感谢大家的帮助。

最佳答案

尝试在设备/仿真器上卸载应用程序,可能是在没有修改的列的情况下创建了数据库的情况。

编辑:

// 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" + ");";

您永远不会在此处定义“已修改”列...

关于android - Android SQL崩溃-没有这样的专栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11780998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com