My application has a SQLite database in the asset folder. When the user launches my application, the database is created and the tables too.
This works fine with a lot of devices (Nexus One, Htc Magic, SGS, X10… and even Htc Desire HD v2.2).
My application works with all versions of Android (tested on my device (1.6, 2.2, 2.2.1 Htc Magic) and on the emulator (v1,5 until v2.3).
I have just a problem with HTC DESIRE HD v2.2.1 1.72.405.3.
The logcat:
android.database.sqlite.SQLiteException: no such table: LISTE: , while compiling: select _id from LISTE
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2833)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2854)
at android.app.ActivityThread.access$2300(ActivityThread.java:136)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5068)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: no such table: LISTE: , while compiling: select _id from LISTE
at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:64)
at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:80)
at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:46)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1417)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1387)
... 11 more
My application create the database but it doesn’t copy the tables of the file of the asset folder in data\data\packagename\databases\mydatabase.
My code:
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
//do nothing - database already exist
}else{
//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))!= -1){
if (length > 0){
myOutput.write(buffer, 0, length);
} }
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
I think that the copydatabase function has a problem but I don't see.
This code works fine with all devices except the HTC DESIRE HD v2.2.1 1.72.405.3.
What problems might exist here for the HTC Desire with the given version above? How can this be remedied?