无法将数据库的区域设置更改为' en_US'

时间:2016-02-19 09:04:47

标签: java android sqlite

我查看了有关此问题的所有链接,但无法获得任何线索。我收到的异常报告来自Google Developer Console。我在Nexus 4 Device中尝试了代码,它工作正常。

下面是我的堆栈跟踪&码。任何人都可以找到发生异常的原因。

堆栈跟踪

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)

使用的代码

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);
    }
}

1 个答案:

答案 0 :(得分:-1)

在这篇文章中

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

他们通过改变

解决了这个问题
myDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

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

虽然因为我在使用它,但它并不适用于我 dbHelper.getReadableDatabase()

显然无法通过NO_LOCALIZED_COLLATORS指定SQLiteOpenHelper之类的标记,因此您必须扩展自己的SQLiteOpenHelper版本并在openDatabase()方法中指定标记那里。

我的问题出现在Android Studio模拟器上,用于API23平板电脑,而不是其他任何地方。 我不知道这与所提到的标志有什么关系,但在我的情况下,我增加了模拟器的内存后错误消失了。

Android以神秘的方式工作,我猜......