8

For some reason the database handling solution described in this article doesn't work on the HTC Desire HD after it got the OTA update to 2.2.1 (1.72.405.3). It worked on Desire HD before the update and I've failed to reproduce the error on actual devices running 2.1, 2.2 as well as in emulator running all versions.

Unfortunately you can't created a AVD for emulator running Android 2.2.1 and I've tried a ROM based on 2.2.1 (I have a rooted ordinary HTC Desire) but my application works without problem on it as well. So the question is if it's using the Android SDK in some way it shouldn't that all of a sudden cause the problem?

I know this is a very specific issue but since more developers than me reporting the problem as well as the fact that you can't create an AVD I hope the question is accepted and I hope someone have a clue what might causing the problem.

Here's a stack trace sent to my Market account by user:

Caused by: android.database.sqlite.SQLiteDiskIOException: disk I/O error
at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:2049)
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1917)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:889)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:168)
at com.MyApp.DataBaseHelper.createDataBase(DataBaseHelper.java:81)
at com.MyApp.InitialActivity.onCreate(InitialActivity.java:33)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2797)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1066)  

Related methods can be found at pastebin. Since only one hyperlink can be included link could be found in comments below. Note that line 81 found in stack trace is line 10 at pastebin.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Björn
  • 876
  • 1
  • 10
  • 19
  • Additional comments from other users about the same issue can be read from this comment and below: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/comment-page-4/#comment-43655 – Björn Jan 10 '11 at 21:41
  • is the locale en_US not available on the new Android 2.2.1 version? From the Android source SQLiteDatabase.setLocale: "@throws SQLException if the locale could not be set. The most common reason for this is that there is no collator available for the locale you requested." – Phyrum Tea Jan 10 '11 at 23:18
  • It should be alright. My sqlite-db looks like this: CREATE TABLE android_metadata (locale TEXT); INSERT INTO android_metadata VALUES('en_US'); I've also added flag NO_LOCALIZED_COLLATORS to call to SQLiteDatabase.openDatabase() but that didn't help either. I get the feeling the database is corrupt before it tries to open it and read locale. – Björn Jan 11 '11 at 07:18
  • 1
    This question seem to be related to this one: http://stackoverflow.com/questions/4585790/problem-with-testing-and-debuging-of-android-apps – Björn Jan 12 '11 at 05:51
  • As well as this thread http://stackoverflow.com/questions/4718934/sqlite-issues-with-htc-desire-hd Wish for a more detailed explanation of how the user of this thread solved the issue. – Björn Jan 19 '11 at 10:15

2 Answers2

6

I finally seem to have got my app to work on Android 2.2.1 on Desire HD. I haven’t had the chance to debug on it personally to try out exactly what’s causing the problem.

One thought that popped up is the hard coded path to where the database file is located. DB_PATH = “/data/data/YOUR_PACKAGE/databases/”;

I guess it is possible that this path isn’t valid on Android 2.2.1 for Desire HD. I exchanged this path with: Environment.getDataDirectory() + “/data/YOUR_PACKAGE/databases/” + DB_NAME;

I’ll try to pin point the issue when I had the chance to test on the actual phone myself. If anyone test this solution, please let me know if it solves it.

Björn
  • 876
  • 1
  • 10
  • 19
0

as well as the excellent answer from Björn, this link worked for me:

Link on AndDev.org

It seems you have to specificly close the return of this.getReadableDatabase();

ben_the_builder
  • 309
  • 2
  • 8