hi my application contains SQLite .My application some time getting the following error
java.lang.RuntimeException: Unable to destroy activity {com.fitzsoftware.grocessaryList/com.fitzsoftware.grocessaryList.GrocessaryList}: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3655)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3673)
at android.app.ActivityThread.access$2900(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.database.sqlite.SQLiteDatabase.dbclose(Native Method)
at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:320)
at android.database.sqlite.SQLiteDatabase.close(SQLiteDatabase.java:881)
at com.fitzsoftware.grocessaryList.GrocessaryList.onDestroy(GrocessaryList.java:103)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3642)
I am closing the db in Destroy() using DataClass.dh.db.close();
Why this Error occured.Give me the solutions for this.Thanks in advance.
I'm late to the party, but I just saw this. In my case, I had created a Cursor object from a database query, then accidentally closed the database before I closed the cursor. Check whether this is what's happening.
As well Gareth Lloyd's answer, from what I've read of other threads, another cause of this exception is not closing Cursor objects, i.e. attempting to close your SQLiteDatabase instance before closing Cursor objects that have been obtained from querying your SQLiteDatabase instance.
Related
I have ocassional crash at my emulator, but for now never on tablet on which I am testing.
java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:346)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:375)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:373)
at java.util.HashMap.writeObject(HashMap.java:1024)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1229)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1215)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1859)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1701)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1665)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1153)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:420)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1251)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1859)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1701)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1665)
at android.os.Parcel.writeSerializable(Parcel.java:1155)
at android.os.Parcel.writeValue(Parcel.java:1114)
at android.os.Parcel.writeMapInternal(Parcel.java:479)
at android.os.Bundle.writeToParcel(Bundle.java:1552)
at android.os.Parcel.writeBundle(Parcel.java:493)
at android.app.ActivityManagerProxy.activityPaused(ActivityManagerNative.java:1574)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3292)
at android.app.ActivityThread.access$2500(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
It seems from the log it happens when the activity is going to pause.
All my activity are accessing a common super class static object (global data), which indeed has some linkedhashmap inside, and I am saving this globaldata with putSerializable inside onSaveInstanceState. I have tried to put save/restore of globaldata inside my base activity class inside sattic synchronized methods, but it didn't helped.
My I know from yours experiences if this is some internal android bug (maybe just emulator bug) or If I am managing saving of global data (which has LinkedHashMap inside) wrong. Or is there another way to share common data between activites?
Thanks
I have a bound service running multiple threads that read and write to an SQLite database. I create an instance of my database helper and get a connection to the database in the onCreate of my service, which should execute on the main thread. As it's a bound service there should only ever be one instance of the service in memory. However i still get
exceptions occasionally when the service tries to open the database or when one of the threads tries to execute a statement.
Service code:
#Override
public void onCreate() {
super.onCreate();
MyDatabaseHelper helper = new MyDatabaseHelper(this);
database = helper.getWritableDatabase();
}
Exceptions:
java.lang.RuntimeException: Unable to create service uk.co.example.service.MyService:
android.database.sqlite.SQLiteException: unable to open database file
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1959)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: unable to open database file
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1960)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:887)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:965)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:958)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:585)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
at uk.co.example.service.MyService.onCreate(MyService.java:69)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1949)
... 10 more
android.database.sqlite.SQLiteException: error code 5: database is locked
at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61)
at uk.co.example.a.a.a.a(MyTable.java:147)
at uk.co.example.service.b.a.m.run(MySaveTask.java:84)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
Any ideas what could be causing this?
Thanks
David
Sqlite now supports a new journal mode called Writing-Ahead Logging, which is suitable for concurrent access to sqlite. you may want to take a look at http://www.sqlite.org/wal.html.
I am getting crash reports from sporadic SQLiteExceptions in my application. I am not directly interacting with SQLite databases at all. I have tracked the code down to the usage of the WebView widget. The exceptions differ in cause, but a couple of examples are as follows...
android.database.sqlite.SQLiteException: database is locked: BEGIN EXCLUSIVE;
at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1768)
at android.database.sqlite.SQLiteDatabase.beginTransactionWithListener(SQLiteDatabase.java:558)
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:512)
at android.webkit.WebViewDatabase.startCacheTransaction(WebViewDatabase.java:603)
at android.webkit.CacheManager.enableTransaction(CacheManager.java:251)
at android.webkit.WebViewWorker.handleMessage(WebViewWorker.java:214)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.os.HandlerThread.run(HandlerThread.java:60)
Another example...
java.lang.RuntimeException: Unable to create application com.example.MyApplication: android.database.sqlite.SQLiteException: near "VALUES": syntax error: , while compiling: INSERT INTO cache (VALUES (
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3828)
at android.app.ActivityThread.access$2200(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1082)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: near "VALUES": syntax error: , while compiling: INSERT INTO cache (VALUES (
at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1231)
at android.database.DatabaseUtils$InsertHelper.getStatement(DatabaseUtils.java:858)
at android.database.DatabaseUtils$InsertHelper.getColumnIndex(DatabaseUtils.java:904)
at android.webkit.WebViewDatabase.getInstance(WebViewDatabase.java:397)
at android.webkit.WebView.<init>(WebView.java:1077)
at android.webkit.WebView.<init>(WebView.java:1054)
at android.webkit.WebView.<init>(WebView.java:1044)
at android.webkit.WebView.<init>(WebView.java:1035)
at com.example.MyApplication.getWebView(MyApplication.java:223)
at com.example.MyApplication.loadUrlInWebView(MyApplication.java:249)
at com.example.MyApplication.onCreate(MyApplication.java:169)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:984)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3825)
... 10 more
Why might these crashes be occurring? Has anyone else had this problem?
Note: The platform in the error reports are each listed as OTHER, so maybe this is only happening in an emulator or unofficial build of the OS.
This is probably related to the webview DOM storage. See WebSettings.setDatabaseEnabled and WebSettings.setDatabasePath.
http://developer.android.com/reference/android/webkit/WebSettings.html#setDatabaseEnabled(boolean)
http://developer.android.com/reference/android/webkit/WebSettings.html#setDatabasePath(java.lang.String)
A common complaint is that the DOM storage does not work, and that is usually fixed with code like this:
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setDatabasePath("/data/data/packagename/databases/");
I never heard of crash problems with this, but it may be worth investigating what happens when you disable DOM storage and when you specify a proper database path (as shown above using your app's packagename).
This thread may also be helpful:
Android - Making Webview DomStorage persistant after app closed
Does anyone know what this could possibly mean? Apparently someone else's app caused mine to crash? And it happens to be an app that directly competes with mine:
java.lang.RuntimeException: Unable to create BackupAgent com.MY_COMPEITOR'S_APP.backup.BackupAgent: java.lang.NullPointerException
at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2905)
at android.app.ActivityThread.access$4000(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2128)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.ActivityThread$PackageInfo.initializeJavaContextClassLoader(ActivityThread.java:529)
at android.app.ActivityThread$PackageInfo.getClassLoader(ActivityThread.java:474)
at android.app.ActivityThread.handleCreateBackupAgent(ActivityThread.java:2873)
... 10 more
TenFour I would bet since you are talking about a competing App that there must be some INtent Handling going on that led to this. Maybe the Competitor app was actually trying to do something at the same time your app was trying to do something and they clashed. Without knowing more it's hard to provide a more detailed answer
I am getting a crash report back that says OutOfMemoryError in my call to startManagingCursor. Here is the returned stack trace:
java.lang.OutOfMemoryError
at java.util.ArrayList.add(ArrayList.java:123)
at android.app.Activity.startManagingCursor(Activity.java:1652)
at com.bubblewaretechnology.pianounlockscreen.LockDetecter.onResume(LockDetecter.java:633)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.ActivityThread.performNewIntents(ActivityThread.java:1789)
at android.app.ActivityThread.handleNewIntent(ActivityThread.java:1795)
at android.app.ActivityThread.access$2300(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1015)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
I am very careful to close my cursors, SQLiteDatabase and SQLiteOpenHelper. Here is a short code segment that the crash refers to:
Cursor callCursor = lockLib.getCallState();
startManagingCursor(callCursor);
....
callCursor.close();
Pretty stumped on how to go about troubleshooting this problem. I know startManagingCursor is depreciated but I am not targeting HONEYCOMB or later, so I cant switch to CursorLoader. Does anyone have any suggestions on how to proceed?
I know it's lame to answer your own question but you can remove startManagingCursor, Reference Link, as long as you are managing the lifecycle of your cursor appropriately.