2016-02-19 39 views
2

我經歷了有關此問題的所有鏈接,但無法獲取有關此問題的任何線索。我收到的例外報告來自Google Developer Console。我試過Nexus 4 Device中的代碼,它的工作正常。無法將db的語言環境更改爲'en_US'

以下是我的堆棧跟蹤&代碼。任何人都可以找到發生異常的原因。

堆棧跟蹤

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

http://stackoverflow.com/questions/11213436/database-locked-exception – Sree

+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()

而顯然沒有通過SQLiteOpenHelper指定如NO_LOCALIZED_COLLATORS標誌的方式,所以您必須擴展您自己的SQLiteOpenHelper版本並在那裏指定openDatabase()方法中的標誌。

我的問題出現在API Studio平板電腦和其他地方的Android Studio模擬器上。 我不知道這是如何與提到的國旗,但在我的情況下,錯誤消失後,我增加了模擬器的內存。

Android版以神祕的方式,我想..

相關問題