4

I go through all the link regarding this issue, but not able to get any clue on that. The exception report I got is from Google Developer Console. I tried the code to in Nexus 4 Device, its working fine.

Below is my stack trace & Code. Can anyone found why the exception is happening.

Stack Trace

Fatal Exception: android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/in.plackal.lovecyclesfree/databases/LoveCycles.db' to 'en_US'.
       at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:399)
       at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:224)
       at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:199)
       at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
       at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
       at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
       at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
       at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
       at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
       at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:1167)
       at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:268)
       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
       at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
       at in.plackal.lovecyclesfree.database.DatabaseOperations.open(DatabaseOperations.java:85)
       at in.plackal.lovecyclesfree.general.CycleManager.readSettings(CycleManager.java:7724)
       at in.plackal.lovecyclesfree.applicationwidget.WidgetTodayService.getValueFromCycleManager(WidgetTodayService.java:51)
       at in.plackal.lovecyclesfree.applicationwidget.WidgetTodayService.onHandleIntent(WidgetTodayService.java:37)
       at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:211)
       at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5)
       at android.database.sqlite.SQLiteConnection.nativeExecute(SQLiteConnection.java)
       at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:561)
       at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:390)
       at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:224)
       at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:199)
       at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
       at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
       at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
       at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
       at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
       at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
       at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:1167)
       at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:268)
       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
       at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
       at in.plackal.lovecyclesfree.database.DatabaseOperations.open(DatabaseOperations.java:85)
       at in.plackal.lovecyclesfree.general.CycleManager.readSettings(CycleManager.java:7724)
       at in.plackal.lovecyclesfree.applicationwidget.WidgetTodayService.getValueFromCycleManager(WidgetTodayService.java:51)
       at in.plackal.lovecyclesfree.applicationwidget.WidgetTodayService.onHandleIntent(WidgetTodayService.java:37)
       at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:211)
       at android.os.HandlerThread.run(HandlerThread.java:61)

Code Used

public class DatabaseOperations
{
    private Context m_Context;

    private DataBaseWrapper dbHelper;

    private SQLiteDatabase database;

    public DatabaseOperations(Context context)
    {
        m_Context = context;
        dbHelper = new DataBaseWrapper(context);
    }

    public void open() throws SQLException
    {
        database = dbHelper.getWritableDatabase();
    }

    public void close()
    {
        dbHelper.close();
    }
}


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseWrapper extends SQLiteOpenHelper 
{
    // Database Name
    private static final String DATABASE_NAME = "TestDB.db";

    // Database Version
    private static final int DATABASE_VERSION = 2;


    public DataBaseWrapper(Context context) 
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);  
    }

    @Override
    public void onCreate(SQLiteDatabase db) 
    {               
        db.execSQL(CREATE_CYCLE_TABLE);
        db.execSQL(CREATE_NOTES_TABLE);
            db.execSQL(CREATE_SETTINGS_TABLE);
        }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {

    }

    @Override
    public void onOpen(SQLiteDatabase db)
    {
        super.onOpen(db);
    }
}
AndroidDev
  • 4,521
  • 24
  • 78
  • 126

1 Answers1

-1

In this post

Failed to change locale for db '/data/data/my.easymedi.controller/databases/EasyMediInfo.db' to 'en_US'

they solved it by changing

myDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

to

myDatabase = SQLiteDatabase.openDatabase
(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE);

It didn't work for me though because I was using dbHelper.getReadableDatabase()

And apparently there is no way of specifying flags like NO_LOCALIZED_COLLATORS through SQLiteOpenHelper, so you have to extend your own version of SQLiteOpenHelper and specify the flag in openDatabase() method there.

I had the issue appearing on Android Studio emulator for API23 tablet and nowhere else. I don't know how this has anything to do with the mentioned flag but in my case error disappeared after I increased memory of the emulator.

Android works in mysterious ways, I guess..

Community
  • 1
  • 1