次の行を含むすべてのデータベース変数を含むファイルがあります。
public static final String TABLE_CONFERENCES = "conferences";
私のSQLiteOpenHelperはデータベースを作成し、すべてが正常に機能するかどうかをテストします。その後、テーブルが作成されたことを確認します。
db.beginTransaction();
...
db.execSQL(DatabaseConstants.CREATE_TABLE_CONFERENCES);
...
db.endTransaction();
Log.d(TAG, "testing successful create execution");
db.execSQL("SELECT * FROM " + DatabaseConstants.TABLE_CONFERENCES);
Log.d(TAG, "executed create statements successfully");
テーブルにいくつかのテストデータを入力し、結果をログに記録して、エラーが発生していないことを確認します。
values = new ContentValues();
cal.set(2020, 1, 1, 12, 30, 0);
values.put(DatabaseConstants.CONFERENCE_START, cal.getTimeInMillis());
cal.set(2021, 6, 6, 13, 30, 0);
values.put(DatabaseConstants.CONFERENCE_END, cal.getTimeInMillis());
values.put(DatabaseConstants.CONFERENCE_CREATOR, lastInsertId);
conferenceID = lastInsertId = db.insert(DatabaseConstants.TABLE_CONFERENCES, null, values);
Log.d(TAG, "inserted ConferenceId: " + Long.toString(lastInsertId));
cursor = db.query(
DatabaseConstants.TABLE_CONFERENCES,
new String[] { DatabaseConstants.CONFERENCE_ID },
DatabaseConstants.CONFERENCE_ID + "=" + lastInsertId,
null,
null,
null,
null,
null);
Log.d(TAG, "inserted Conference successfully");
cursor.moveToFirst();
Log.d(TAG,
"Conference has " + DatabaseConstants.PARTICIPANT_ID + ": " +
Long.toString(cursor.getLong(cursor.getColumnIndex(DatabaseConstants.CONFERENCE_ID))));
cursor.close();
次のメソッドを含む会議用のデータソースをコーディングしました。
public Conference getConference(long conferenceId) {
Log.d(TAG, "getConference with conferenceId " + conferenceId + " called");
/*
* query(table, columns, selection, selectionArgs, groupBy, having, orderBy)
*/
Cursor cursor = database.query(
DatabaseConstants.TABLE_CONFERENCES,
fields,
DatabaseConstants.CONFERENCE_ID + "=" + conferenceId,
null,
null,
null,
null);
cursor.moveToFirst();
Conference conference = cursorToConference(cursor);
cursor.close();
return conference;
}
しかし、上記のメソッドを呼び出している場合。次のエラーが発生します。
04-20 14:39:28.669: D/ConferenceDataSource(1300): getConference with conferenceId 1 called
04-20 14:39:28.669: I/SqliteDatabaseCpp(1300): sqlite returned: error code = 1, msg = no such table: conferences, db=/data/data/com.tsystems.openconf/databases/OpenConf_App.Prototype.1.5
04-20 14:39:28.729: D/AndroidRuntime(1300): Shutting down VM
04-20 14:39:28.729: W/dalvikvm(1300): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-20 14:39:28.879: E/AndroidRuntime(1300): FATAL EXCEPTION: main
04-20 14:39:28.879: E/AndroidRuntime(1300): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tsystems.openconf/com.tsystems.openconf.dashboard.item.ConferenceTableActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tsystems.openconf/com.tsystems.openconf.tab.ConferenceInfoActivity}: android.database.sqlite.SQLiteException: no such table: conferences: , while compiling: SELECT _id, startTime, endTime, creator FROM conferences WHERE _id=1
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.os.Looper.loop(Looper.java:137)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-20 14:39:28.879: E/AndroidRuntime(1300): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 14:39:28.879: E/AndroidRuntime(1300): at java.lang.reflect.Method.invoke(Method.java:511)
04-20 14:39:28.879: E/AndroidRuntime(1300): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-20 14:39:28.879: E/AndroidRuntime(1300): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-20 14:39:28.879: E/AndroidRuntime(1300): at dalvik.system.NativeStart.main(Native Method)
04-20 14:39:28.879: E/AndroidRuntime(1300): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tsystems.openconf/com.tsystems.openconf.tab.ConferenceInfoActivity}: android.database.sqlite.SQLiteException: no such table: conferences: , while compiling: SELECT _id, startTime, endTime, creator FROM conferences WHERE _id=1
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1797)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:682)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.widget.TabHost.setCurrentTab(TabHost.java:346)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.widget.TabHost.addTab(TabHost.java:236)
04-20 14:39:28.879: E/AndroidRuntime(1300): at com.tsystems.openconf.dashboard.item.ConferenceTableActivity.onCreate(ConferenceTableActivity.java:55)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.Activity.performCreate(Activity.java:4465)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-20 14:39:28.879: E/AndroidRuntime(1300): ... 11 more
04-20 14:39:28.879: E/AndroidRuntime(1300): Caused by: android.database.sqlite.SQLiteException: no such table: conferences: , while compiling: SELECT _id, startTime, endTime, creator FROM conferences WHERE _id=1
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1449)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1485)
04-20 14:39:28.879: E/AndroidRuntime(1300): at com.tsystems.openconf.database.dataSource.ConferenceDataSource.getConference(ConferenceDataSource.java:100)
04-20 14:39:28.879: E/AndroidRuntime(1300): at com.tsystems.openconf.tab.ConferenceInfoActivity.onCreate(ConferenceInfoActivity.java:34)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.Activity.performCreate(Activity.java:4465)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-20 14:39:28.879: E/AndroidRuntime(1300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-20 14:39:28.879: E/AndroidRuntime(1300): ... 21 more
04-20 14:39:28.988: D/dalvikvm(1300): GC_CONCURRENT freed 215K, 3% free 9321K/9607K, paused 8ms+9ms
04-20 14:39:29.109: E/SQLiteDatabase(1300): close() was never explicitly called on database '/data/data/com.tsystems.openconf/databases/OpenConf_App.Prototype.1.5'
04-20 14:39:29.109: E/SQLiteDatabase(1300): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1943)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1007)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1051)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:770)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at com.tsystems.openconf.database.dataSource.ConferenceDataSource.open(ConferenceDataSource.java:41)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at com.tsystems.openconf.tab.ConferenceInfoActivity.onCreate(ConferenceInfoActivity.java:32)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.Activity.performCreate(Activity.java:4465)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1797)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:682)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.widget.TabHost.setCurrentTab(TabHost.java:346)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.widget.TabHost.addTab(TabHost.java:236)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at com.tsystems.openconf.dashboard.item.ConferenceTableActivity.onCreate(ConferenceTableActivity.java:55)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.Activity.performCreate(Activity.java:4465)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.os.Looper.loop(Looper.java:137)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at java.lang.reflect.Method.invoke(Method.java:511)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-20 14:39:29.109: E/SQLiteDatabase(1300): at dalvik.system.NativeStart.main(Native Method)
04-20 14:39:29.109: E/System(1300): Uncaught exception thrown by finalizer
04-20 14:39:29.139: E/System(1300): java.lang.IllegalStateException: Don't have database lock!
04-20 14:39:29.139: E/System(1300): at android.database.sqlite.SQLiteDatabase.verifyLockOwner(SQLiteDatabase.java:2090)
04-20 14:39:29.139: E/System(1300): at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2182)
04-20 14:39:29.139: E/System(1300): at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2178)
04-20 14:39:29.139: E/System(1300): at android.util.LruCache.trimToSize(LruCache.java:197)
04-20 14:39:29.139: E/System(1300): at android.util.LruCache.evictAll(LruCache.java:285)
04-20 14:39:29.139: E/System(1300): at android.database.sqlite.SQLiteDatabase.deallocCachedSqlStatements(SQLiteDatabase.java:2143)
04-20 14:39:29.139: E/System(1300): at android.database.sqlite.SQLiteDatabase.closeClosable(SQLiteDatabase.java:1126)
04-20 14:39:29.139: E/System(1300): at android.database.sqlite.SQLiteDatabase.finalize(SQLiteDatabase.java:1914)
04-20 14:39:29.139: E/System(1300): at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:182)
04-20 14:39:29.139: E/System(1300): at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)
04-20 14:39:29.139: E/System(1300): at java.lang.Thread.run(Thread.java:856)
ヘルプ!エラーの検索をどこから始めればよいかわからない。