android sqlite:无法将db的语言环境更改为“zh_CN”

时间:2014-01-16 07:19:20

标签: android sqlite corruption

存在类似的问题,

  

android.database.sqlite.SQLiteException:无法更改区域设置   db引起:android.database.sqlite.SQLiteDatabaseCorruptException:   数据库磁盘映像格式错误(代码11)

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

但我的数据库是由android通过SQLiteOpenHelper创建的。它出现在一些设备中。 我想知道是什么原因导致这个问题,因为我甚至无法重现它。 我怎么解决这个问题? 非常感谢!

android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/com.android.settings/databases/myDB.db' to 'zh_CN'.
at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:386)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
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:804)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:833)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at com.example.optimizecenter.packages.e.mO(PackagesManager.java:150)
at com.example.optimizecenter.packages.PackageSyncService.onHandleIntent(PackageSyncService.java:24)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
Caused by: android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed (code 11)
at android.database.sqlite.SQLiteConnection.nativeExecuteForString(Native Method)
at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:634)
at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:367)
... 18 more

这是我的帮助班。

public class PackageDataBaseHelper extends SQLiteOpenHelper {

    public PackageDataBaseHelper(Context context) {
        super(context, PackageColumns.DB_NAME, null, PackageColumns.DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        StringBuilder sb = new StringBuilder();
        sb.append("create table ");
        sb.append(PackageColumns.TABLE_PACKAGE);
        sb.append(" (");
        sb.append(PackageColumns._ID + " integer primary key autoincrement, ");
        sb.append(PackageColumns.COLUMN_APPLICATION_LABEL + " TEXT ,");
        sb.append(PackageColumns.COLUMN_PACKAGE_NAME + " TEXT ,");
        sb.append(PackageColumns.COLUMN_VERSION_NAME + " TEXT ,");
        sb.append(PackageColumns.COLUMN_VERSION_CODE + " INTEGER ,");
        sb.append(PackageColumns.COLUMN_IC_LAUNCHER + " BOLD");
        sb.append(");");
        db.execSQL(sb.toString());
    }

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

}

1 个答案:

答案 0 :(得分:2)

SQLiteDatabase db=SQLiteDatabase.openDatabase("/data/data/com.android.settings/databases/myDB.db", null,SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.CREATE_IF_NECESSARY);

尝试使用此代码示例代码..

如果您有sqlite浏览器,请打开您的数据库.. 在您的数据库中,android_metadata表的区域设置似乎不是 en_US