Saturday, September 7, 2013

Re: [android-developers] Re: SQLiteException: error code 5: database is locked. When accessing ContentProvider from AsyncTask

I figured it out and yes I was using multiple databases. One per provider. So you're right this is what was causing the issue! :-)


On 7 September 2013 20:14, Nobu Games <dev.nobu.games@gmail.com> wrote:
This error can happen when you try to open the same database (file) multiple times. Which in turn can happen when you are using multiple instances of SQLiteOpenHelper. So where do you create the instance of "database"?


On Saturday, September 7, 2013 8:52:44 AM UTC-5, Eurig Jones wrote:
Quite frequently I get the following exception and I'm really entirely sure what to do about it.

    java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:200)
        at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        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)
    Caused by: 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 android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1704)
        at azurewing.android.db.provider.NotificationProvider.delete(NotificationProvider.java:80)
        at azurewing.android.db.provider.Provider.delete(Provider.java:87)
        at azurewing.android.db.provider.NotificationProvider.delete(NotificationProvider.java:1)
        at android.content.ContentProvider$Transport.delete(ContentProvider.java:234)
        at android.content.ContentResolver.delete(ContentResolver.java:692)
        at azurewing.android.db.table.NotificationTable.removeAllNotifications(NotificationTable.java:89)
        at azurewing.android.sync.SyncReceiver$1$1.doInBackground(SyncReceiver.java:52)
        at azurewing.android.sync.SyncReceiver$1$1.doInBackground(SyncReceiver.java:1)
        at android.os.AsyncTask$2.call(AsyncTask.java:185)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
        ... 4 more

I am accessing a ContentProvider (NotificationProvider here) via an AsyncTask. The ContentProvider uses a database of course.

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs)
    {
        SQLiteDatabase  db = database.getWritableDatabase();
        int numDeleted = database.delete(NotificationTable.TABLE_NAME, selection, selectionArgs);
        return numDeleted;
    }

I'm a bit stumped about what to do here. It's clearly a threading issue I think, so I'm thinking of everytime I get the database, I do it from a synchronized method in 1 class. Is this a good idea?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Android Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-developers/0PuIfWyRfUI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate