Missing table in SQLite with specific version of HTC DESIRE HD

My application has an SQLite database in its asset folder. When a user launches my application, a database and tables are created.

This works great with many 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 to v2.3).

I only have a problem with HTC DESIRE HD v2.2.1 1.72.405.3.

Log Code:

android.database.sqlite.SQLiteException: no such table: LISTE: at compilation: 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) on android.os.Handler.dispatchMessage (Handler.java:99) on android.os.Looper.loop (Looper.java:143) at android.app.ActivityThread.main (ActivityThread.java:5068) in java.lang.reflect.Method.invokeNative (native method) in java.lang.reflect. Method.invoke (Method.javaPoint21) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:858) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616) in dalvik.system.NativeStart.main (native method) Called: android.database.sqlite.SQLiteExcept ion: no such table: LISTE: at compilation: select _id from LISTE in the file android.database.sqlite.SQLiteCompiledSql.native_compile (native method) in the file android.database.sqlite.SQLiteCompiledSql.compile (SQLiteCompiledSql.java:91) in the file android.database.sqlite.SQLiteCompiledSql. (SQLiteCompiledSql.java:64) in android.database.sqlite.SQLiteProgram. (SQLiteProgram.java:80) in android.database.sqlite.SQLiteQuery. (SQLiteQuery.java:46) in android.database.sqlite.SQLiteDirectCursorDriver.query (SQLiteDirectCursorDriver.java:53) in android.database.sqlite.SQLiteDatabase.rawQueryWithFactory (SQLiteDatabase.java:1417) in android.database.sqlite.qliteSQL rawQuery (SQLiteDatabase.java:1387) ... 11 more

My application creates a database, but it does not copy the file tables of the resource folder to data\data\packagename\databases\mydatabase .

My code is:

 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 the copydatabase function has a problem, but I do not see.

This code works great with all devices except HTC DESIRE HD v2.2.1 1.72.405.3.

What problems can arise here for HTC Desire with the above version? How can this be fixed?

+7
source share
1 answer

This is a little guess and implies that there is a “bug” in this version of Android for Desire HD, so I might be out of the game.

I am wondering if this version of Android will not create a database where it should work. You assume that DB_PATH is \ data \ data \ packagename \ databases \, as usual, but what if it is not? The result will be the following ...

  • this.getReadableDatabase() will create an empty database in \ some \ correct \ path \ mydatabase
  • Using new FileOutputStream(outFileName) simply creates a new empty binary file because the database above was not created in the place you expect.
  • Copy completed successfully.
  • Before executing a SELECT query, access to the database is requested using getReadableDatabase() or getWriteableDatabase() , but both of them simply open the empty database created in step 1.

In short, the copy process may have worked correctly, but the working database is empty and in another place where you expect.

Just an idea (I saw that such things happen over the years).

0
source

All Articles