当我尝试将记录插入名为“reminders”的表中时,我的应用程序失败了(参见下面的logcat)。我看过20多个类似的帖子,但我无法发现我的错误。这可能是一个明显的错误,但我只能找到它。
logcat的:
02-22 14:10:25.884: E/SQLiteLog(2638): (1) table reminders has no column named title
02-22 14:11:22.935: D/dalvikvm(2638): threadid=11: still suspended after undo (sc=1 dc=1)
02-22 14:11:34.684: W/dalvikvm(2638): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
02-22 14:11:34.684: D/dalvikvm(2638): threadid=1: still suspended after undo (sc=1 dc=1)
02-22 14:11:39.263: D/dalvikvm(2638): threadid=1: still suspended after undo (sc=1 dc=1)
02-22 14:11:40.043: E/AndroidRuntime(2638): FATAL EXCEPTION: ModernAsyncTask #1
02-22 14:11:40.043: E/AndroidRuntime(2638): java.lang.RuntimeException: An error occured while executing doInBackground()
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:137)
02-22 14:11:40.043: E/AndroidRuntime(2638): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-22 14:11:40.043: E/AndroidRuntime(2638): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-22 14:11:40.043: E/AndroidRuntime(2638): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-22 14:11:40.043: E/AndroidRuntime(2638): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-22 14:11:40.043: E/AndroidRuntime(2638): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-22 14:11:40.043: E/AndroidRuntime(2638): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-22 14:11:40.043: E/AndroidRuntime(2638): at java.lang.Thread.run(Thread.java:856)
02-22 14:11:40.043: E/AndroidRuntime(2638): Caused by: java.lang.IllegalArgumentException: Unknown Uri: content://com.example.android.taskreminder.ReminderProvider/reminder
02-22 14:11:40.043: E/AndroidRuntime(2638): at com.example.taskreminder.ReminderProvider.query(ReminderProvider.java:138)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.content.ContentProvider.query(ContentProvider.java:652)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.content.ContentProvider$Transport.query(ContentProvider.java:189)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.content.ContentResolver.query(ContentResolver.java:370)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.content.ContentResolver.query(ContentResolver.java:313)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:35)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:240)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:51)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:40)
02-22 14:11:40.043: E/AndroidRuntime(2638): at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:123)
02-22 14:11:40.043: E/AndroidRuntime(2638): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-22 14:11:40.043: E/AndroidRuntime(2638): ... 4 more
02-22 14:11:40.333: D/dalvikvm(2638): threadid=1: still suspended after undo (sc=1 dc=1)
02-22 14:11:40.473: D/dalvikvm(2638): threadid=1: still suspended after undo (sc=1 dc=1)
02-22 14:11:40.517: D/dalvikvm(2638): GC_CONCURRENT freed 233K, 3% free 11200K/11527K, paused 91ms+91ms, total 260ms
02-22 14:11:51.376: I/Process(2638): Sending signal. PID: 2638 SIG: 9
以下是相关代码:
private static class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_CREATE = "CREATE TABLE "
+ DATABASE_TABLE + " (" + COLUMN_ROWID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_TITLE
+ " TEXT NOT NULL, " + COLUMN_BODY + " TEXT NOT NULL, "
+ COLUMN_DATE_TIME + " INTEGER NOT NULL);";
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
// Called when the database is created for the first time
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
@Override
public boolean onCreate() {
// Calls getWritableDataBase() on a DatabaseHelper object
mDb = new DatabaseHelper(getContext()).getWritableDatabase();
return true;
}
private static class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_CREATE = "CREATE TABLE "
+ DATABASE_TABLE + " (" + COLUMN_ROWID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_TITLE
+ " TEXT NOT NULL, " + COLUMN_BODY + " TEXT NOT NULL, "
+ COLUMN_DATE_TIME + " INTEGER NOT NULL);";
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
}
public Uri insert(Uri uri, ContentValues values) {
values.remove(ReminderProvider.COLUMN_ROWID);
long id = mDb.insertOrThrow(ReminderProvider.DATABASE_TABLE, null, Values);
getContext().getContentResolver().notifyChange(uri, null);
return ContentUris.withAppendedId(uri, id);
}
下面是传递给上面的db.execSQL(DATABASE_CREATE)调用的String DATABASE_CREATE(取自调试器)的值。
CREATE TABLE提醒(_id INTEGER PRIMARY KEY AUTOINCREMENT,标题TEXT NOT NULL,正文TEXT NOT NULL,reminder_date_time INTEGER NOT NULL);
除非我遗漏了某些东西,否则对我来说是正确的。
无论如何以编程方式(通过方法)在创建数据库之后检索数据库的模式(并通过log.d()显示),以便您可以确认它是使用适当的列创建的吗?我尝试在shell中使用SQLite3命令。似乎数据库存在(即,使用.databases命令,我可以看到名称为/data/data/com.example.taskreminder/databases/data.db的“文件”)。但是,当我尝试查看表(通过.tables命令)时,我没有得到任何结果......但不确定我正确使用它。我可以用什么步骤来诊断这类问题?
顺便说一下,这是我第一次使用这个论坛...所以不确定我是否已经使用了
感谢。