Android One Plus Two: Failed to change locale for db
Asked Answered
R

2

11

I am using Sqlite database in one of my Android project. It works fine in all the devices except One Plus Two device.

I am getting exception while trying to open the database. This is the crashlog.

 12-23 19:14:35.235: E/SQLiteLog(3133): (11) database corruption at line 53216 of [9491ba7d73]
12-23 19:14:35.235: E/SQLiteLog(3133): (11) statement aborts at 7: [SELECT locale FROM android_metadata UNION SELECT NULL ORDER BY locale DESC LIMIT 1] 
12-23 19:14:35.237: E/SQLiteDatabase(3133): Failed to open database '/data/data/com.mycompany.myapp/databases/alcochange.sqlite'.
12-23 19:14:35.237: E/SQLiteDatabase(3133): android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/com.mycompany.myapp/databases/myapp.sqlite' to 'en_US'.

Please click here to see the full crash log

I have seen other questions like that here, I have tried almost every answers, but nothing works. I have tried this and this.

EDIT: The device runs on Oxygen Lollipop.

Rubstone answered 23/12, 2015 at 14:11 Comment(7)
The device model doesn't tell us allot, firmware, rom etc. Is way more helpful as OnePlus devices generally run lots of different configurations.Kaufman
This path /data/data/com.zanec.dryjanuary/databases/alcochange.sqlite/may not exist. Check context.getDatabasePath(/data/data/com.zanec.dryjanuary/databases/alcochange.sqlite/) which return File type.Bashful
Do you have a line E/SQLiteDatabase(6278): Caused by: ??? in your crashlog?Hauler
@MadhukarHebbar I've checked that, its fine. This happens only in One Plus Two mobile, its working fine in other mobiles.Rubstone
@naXa yes, there is. Caused by: android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed (code 11).Rubstone
DId you find any solution to the specific issue?Grasp
@Grasp Didn't find the reason, but somehow avoided. Plz see my answer belowRubstone
R
2

I can't find the reason why I am having this error, but somehow I have avoided this by doing the following.

Previously, I had a .sqlite database in the bundle and when the user open our app for the first time, I copied the .sqlite database from the bundle to the correct path.

But now, I have exported the raw queries from the .sqlite and added it with the bundle as a txt file. Now when the user opens the app for the first time, I will first create an empty .sqlite file in the path and then I read all the .sql queries from the txt file from the bundle and execute them over the .sqlite file in the path.

Rubstone answered 4/2, 2016 at 20:40 Comment(0)
H
1

Try to change locale manually.

Open your database file with a SQLite editor such as SQLiteStudio, then open android_metadata table. if it does not exist, create it. (you may create it with the query editor (tools>open query editor) and copy/paste the DDL code below)

CREATE TABLE android_metadata ( 
    locale TEXT 
);

for inserting the record you may copy/paste this line in the query editor:

INSERT INTO android_metadata VALUES ('en_us');

Hint: to run the query in SQLiteStudio you should push the button with lightning icon in the toolbar.

Hauler answered 4/1, 2016 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.