SqLite Database error inside asynctask - android

I run some DB stuff inside an asynctask that runs inside a runnable via handler.postdelayed(r, 30000). It gets repeated (as you can see, every 30 seconds).
Sometimes, not everytime, my app is crashing. Below is the logcat.
09-24 18:28:52.813: W/dalvikvm(6194): threadid=12: thread exiting with uncaught exception (group=0x40daf1f8)
09-24 18:28:52.823: E/AndroidRuntime(6194): FATAL EXCEPTION: AsyncTask #2
09-24 18:28:52.823: E/AndroidRuntime(6194): java.lang.RuntimeException: An error occured while executing doInBackground()
09-24 18:28:52.823: E/AndroidRuntime(6194): at android.os.AsyncTask$3.done(AsyncTask.java:278)
09-24 18:28:52.823: E/AndroidRuntime(6194): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
09-24 18:28:52.823: E/AndroidRuntime(6194): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
09-24 18:28:52.823: E/AndroidRuntime(6194): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
09-24 18:28:52.823: E/AndroidRuntime(6194): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-24 18:28:52.823: E/AndroidRuntime(6194): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
09-24 18:28:52.823: E/AndroidRuntime(6194): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-24 18:28:52.823: E/AndroidRuntime(6194): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-24 18:28:52.823: E/AndroidRuntime(6194): at java.lang.Thread.run(Thread.java:856)
09-24 18:28:52.823: E/AndroidRuntime(6194): Caused by: java.lang.IllegalStateException: database /data/data/com.myApp/databases/mydb.db (conn# 0) already closed
09-24 18:28:52.823: E/AndroidRuntime(6194): at android.database.sqlite.SQLiteDatabase.verifyDbIsOpen(SQLiteDatabase.java:2100)
09-24 18:28:52.823: E/AndroidRuntime(6194): at android.database.sqlite.SQLiteDatabase.lock(SQLiteDatabase.java:418)
09-24 18:28:52.823: E/AndroidRuntime(6194): at android.database.sqlite.SQLiteDatabase.lock(SQLiteDatabase.java:405)
09-24 18:28:52.823: E/AndroidRuntime(6194): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:79)
09-24 18:28:52.823: E/AndroidRuntime(6194): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:164)
09-24 18:28:52.823: E/AndroidRuntime(6194): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:156)
09-24 18:28:52.823: E/AndroidRuntime(6194): at com.myApp.DbAllHelper.dbMethod1(DbAllHelper.java:273)
09-24 18:28:52.823: E/AndroidRuntime(6194): at com.myApp.DbAllHelper.dbMethod2(DbAllHelper.java:582)
09-24 18:28:52.823: E/AndroidRuntime(6194): at com.myApp.MainActivity$checkToInternetOnly.doInBackground(MainActivity.java:278)
09-24 18:28:52.823: E/AndroidRuntime(6194): at com.myApp.MainActivity$checkToInternetOnly.doInBackground(MainActivity.java:1)
09-24 18:28:52.823: E/AndroidRuntime(6194): at android.os.AsyncTask$2.call(AsyncTask.java:264)
09-24 18:28:52.823: E/AndroidRuntime(6194): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

You get somewhere along the logcat an IllegalStateException because the database is already closed. Make sure your background tasks are canceled before you close the database, which is done latest in onDestroy of your Activity.

09-24 18:28:52.823: E/AndroidRuntime(6194): Caused by: java.lang.IllegalStateException: database /data/data/com.myApp/databases/mydb.db (conn# 0) already closed
Are you sure you did not close a Cursor by accident before usage. That or is the asynctask by any chance started twice at some point?
Whatever the reason is, it seems the code at some point is trying to access a closed Cursor.

Related

Facebook Login example runtime exception

My facebook login application fails with the following runtime error:
07-31 12:47:10.195 1309-1316/com.android.quicksearchbox E/jdwp﹕ Failed writing handshake bytes: Broken pipe (-1 of 14)
07-31 12:47:11.004 1341-1358/com.example.apurva.myapplication E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
07-31 12:47:11.094 1341-1360/com.example.apurva.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:781)
at com.facebook.internal.Utility.queryAppSettings(Utility.java:802)
at com.facebook.login.widget.LoginButton$1.doInBackground(LoginButton.java:502)
at com.facebook.login.widget.LoginButton$1.doInBackground(LoginButton.java:499)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
            at java.util.concurrent.FutureTask.run(FutureTask.java:137)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
            at java.lang.Thread.run(Thread.java:856)
A few pointers on what I have done till now:
1)Followed all the requirements in Facebook's Getting Started post.
2)Added the meta-data to the XML.
3)Added the key-hash to facebook
If you see any particular files that might be causing the problem and want to see it before answering, do let me know.

CWAC Camera shows a black blank screen and application crashes while taking picture

All,
I am using the CWAC-Camera-v9 library in my application.
I am seeing a blank screen while the camera launched and the application crashes while taking picture with below error message.
09-24 18:40:08.915: D/PortraitCameraActivity(24228): [DEBUG] Camera takePicture
09-24 18:40:08.920: D/AndroidRuntime(24228): Shutting down VM
09-24 18:40:08.920: W/dalvikvm(24228): threadid=1: thread exiting with uncaught exception (group=0x410f92a0)
09-24 18:40:08.925: D/VM Util(24228): Preview mode must have started before you can take a picture
09-24 18:40:08.925: D/VM Util(24228): java.lang.IllegalStateException: Preview mode must have started before you can take a picture
09-24 18:40:08.925: D/VM Util(24228): at com.commonsware.cwac.camera.CameraView.takePicture(CameraView.java:330)
09-24 18:40:08.925: D/VM Util(24228): at com.commonsware.cwac.camera.CameraFragment.takePicture(CameraFragment.java:162)
09-24 18:40:08.925: D/VM Util(24228): at android.view.View.performClick(View.java:4211)
09-24 18:40:08.925: D/VM Util(24228): at android.view.View$PerformClick.run(View.java:17267)
09-24 18:40:08.925: D/VM Util(24228): at android.os.Handler.handleCallback(Handler.java:615)
09-24 18:40:08.925: D/VM Util(24228): at android.os.Handler.dispatchMessage(Handler.java:92)
09-24 18:40:08.925: D/VM Util(24228): at android.os.Looper.loop(Looper.java:137)
09-24 18:40:08.925: D/VM Util(24228): at android.app.ActivityThread.main(ActivityThread.java:4898)
09-24 18:40:08.925: D/VM Util(24228): at java.lang.reflect.Method.invokeNative(Native Method)
09-24 18:40:08.925: D/VM Util(24228): at java.lang.reflect.Method.invoke(Method.java:511)
09-24 18:40:08.925: D/VM Util(24228): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
09-24 18:40:08.925: D/VM Util(24228): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
09-24 18:40:08.925: D/VM Util(24228): at dalvik.system.NativeStart.main(Native Method)
Any pointers will be really helpful.
EDIT
The test device is Samsung Galaxy S3 GT-I9300. The camera in the native application works fine.
What i am trying to do is to use the camera library in a cross-platform tool called Kony. Kony compiles and integrates the library without any issues. But while launching the camera, i am seeing this issue.
May i know the probable conditions at which the Camera fails to load.
I am trying to launch the MainActivity in the CameraDemo-V9 sample as below
Intent myIntent = new Intent(CamTestActivity.this, com.commonsware.cwac.camera.acl.demo.MainActivity.class);
this.startActivity(myIntent);
This sample is working expected in a Android native project.
--
Thanks,
Sunil
In terms of the exception, you are taking a picture before the preview has been set up, based upon the error message.
In terms of the black screen, off the top of my head I do not know what might cause that. Try running one of the demo apps and see if it behaves properly. If it does not, there may be some incompatibility between the library and your device, in which case I would need to know the specifics of what device you have. If the demo app works, presumably there is something that you are missing in the setup, and so you might compare your code with that of the demo app.

Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging using flex

I am developing an Android native extension for push notification. I have added the gcm library to the class path but the class GoogleCloudMessaging could not be found. Even thought the jar from google is added to the class path of the android project, I still get the error message, so after I export the jar I am updating with the classes from the Google gcm jar. After this everything looks ok at jar level but the problem still persist and I have the following error:
W/dalvikvm(10513): VFY: unable to resolve static method 2592: Lcom/google/android/gms/gcm/GoogleCloudMessaging;.getInstance (Landroid/content/Context;)Lcom/google/android/gms/gcm/GoogleCloudMessaging;
08-17 19:32:10.328: W/dalvikvm(10513): threadid=16: thread exiting with uncaught exception (group=0x40adb9f0)
08-17 19:32:10.348: E/AndroidRuntime(10513): FATAL EXCEPTION: AsyncTask #1
08-17 19:32:10.348: E/AndroidRuntime(10513): java.lang.RuntimeException: An error occured while executing doInBackground()
08-17 19:32:10.348: E/AndroidRuntime(10513): at android.os.AsyncTask$3.done(AsyncTask.java:278)
08-17 19:32:10.348: E/AndroidRuntime(10513): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-17 19:32:10.348: E/AndroidRuntime(10513): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-17 19:32:10.348: E/AndroidRuntime(10513): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-17 19:32:10.348: E/AndroidRuntime(10513): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-17 19:32:10.348: E/AndroidRuntime(10513): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
08-17 19:32:10.348: E/AndroidRuntime(10513): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-17 19:32:10.348: E/AndroidRuntime(10513): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-17 19:32:10.348: E/AndroidRuntime(10513): at java.lang.Thread.run(Thread.java:856)
08-17 19:32:10.348: E/AndroidRuntime(10513): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging
08-17 19:32:10.348: E/AndroidRuntime(10513): at com.microsoft.windowsazure.notifications.NotificationsManager$1.doInBackground(NotificationsManager.java:43)
08-17 19:32:10.348: E/AndroidRuntime(10513): at com.microsoft.windowsazure.notifications.NotificationsManager$1.doInBackground(NotificationsManager.java:1)
08-17 19:32:10.348: E/AndroidRuntime(10513): at android.os.AsyncTask$2.call(AsyncTask.java:264)
08-17 19:32:10.348: E/AndroidRuntime(10513): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-17 19:32:10.348: E/AndroidRuntime(10513): ... 5 more

Android: empty Default HttpClient queue

I have two activities that both make different http requests to my server when started.
When I switch back and forth between them the responses start to have some delay because they get queued up on top of eachother.
I would like to empty and abort this connections and just keep the latest one.
I tried
httpClient.getConnectionManager().shutdown();
but it throws
05-14 08:20:51.137 12627-12997/com.tesis.restapp E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.IllegalStateException: Manager is shut down.
at org.apache.http.impl.conn.SingleClientConnManager.assertStillUp(SingleClientConnManager.java:175)
at org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:213)
at org.apache.http.impl.conn.SingleClientConnManager$1.getConnection(SingleClientConnManager.java:191)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:326)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:580)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:512)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:490)
at support.JSONParser.makeHttpRequest(JSONParser.java:96)
at fragments.MainFragment$FetchOrders.doInBackground(MainFragment.java:150)
at fragments.MainFragment$FetchOrders.doInBackground(MainFragment.java:129)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)...
            
Any other ideas? Thanks
Just cancelling the AsyncTask that carried out the HttpRequest did the trick!

Android Own Cloud error while run in Assync Task

I'm trying to accomplish Reading and Creating folders in the operations Own Cloud server through AsyncTask, login to the server with my credentials is done successfully, but when trying to create folders and read the following errors in the log is described below, which would be the possible reason for the error?
04-07 15:45:24.500: I/OwnCloud(31352): Sending File
04-07 15:45:24.510: I/OwnCloud(31352): Start Read Remote Folder
04-07 15:45:24.620: I/ReadRemoteFolderOperation(31352): Synchronized /: Operation finished with HTTP status code 207 (success)
04-07 15:45:24.630: I/OwnCloud(31352): Sending File
04-07 15:45:24.630: W/dalvikvm(31352): threadid=11: thread exiting with uncaught exception (group=0x40ffe438)
04-07 15:45:24.640: E/AndroidRuntime(31352): FATAL EXCEPTION: AsyncTask #1
04-07 15:45:24.640: E/AndroidRuntime(31352): java.lang.RuntimeException: An error occured while executing doInBackground()
04-07 15:45:24.640: E/AndroidRuntime(31352): at android.os.AsyncTask$3.done(AsyncTask.java:299)
04-07 15:45:24.640: E/AndroidRuntime(31352): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-07 15:45:24.640: E/AndroidRuntime(31352): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-07 15:45:24.640: E/AndroidRuntime(31352): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-07 15:45:24.640: E/AndroidRuntime(31352): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-07 15:45:24.640: E/AndroidRuntime(31352): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-07 15:45:24.640: E/AndroidRuntime(31352): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-07 15:45:24.640: E/AndroidRuntime(31352): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-07 15:45:24.640: E/AndroidRuntime(31352): at java.lang.Thread.run(Thread.java:856)
04-07 15:45:24.640: E/AndroidRuntime(31352): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=5; index=5
04-07 15:45:24.640: E/AndroidRuntime(31352): at com.prologica.procamera.MainActivity$UploadPhotos.SendFolders(MainActivity.java:127)
04-07 15:45:24.640: E/AndroidRuntime(31352): at com.prologica.procamera.MainActivity$UploadPhotos.doInBackground(MainActivity.java:95)
04-07 15:45:24.640: E/AndroidRuntime(31352): at com.prologica.procamera.MainActivity$UploadPhotos.doInBackground(MainActivity.java:1)
04-07 15:45:24.640: E/AndroidRuntime(31352): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-07 15:45:24.640: E/AndroidRuntime(31352): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-07 15:45:24.640: E/AndroidRuntime(31352): ... 5 more
You have an array out of bound in com.prologica.procamera.MainActivity UploadPhotos.SendFolders(MainActivity.java:127). Check line 127 in MainActivity to make sure you are not going out of bounds. According to the log, the length is 5 and you are trying to access index 5(which does not exist)

Categories

Resources