SQLite中缺少特定版本的HTC DESIRE HD

Wil*_*iam 7 sqlite android

我的应用程序在资产文件夹中有一个SQLite数据库.当用户启动我的应用程序时,将创建数据库并创建表.

这适用于很多设备(Nexus One,Htc Magic,SGS,X10 ......甚至是Htc Desire HD v2.2).我的应用程序适用于所有版本的Android(在我的设备上测试(1.6,2.2,2.2.1 Htc Magic)和模拟器(v1,5直到v2.3).

我对HTC DESIRE HD v2.2.1 1.72.405.3只有一个问题.

logcat:

android.database.sqlite.SQLiteException:没有这样的表:LISTE :,编译时:在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2833)的LISTE中选择_id. 2854)在Android.app.Handler.dispatchMessage(Handler.java:99)的android.app.ActivityThread.access $ 2300(ActivityThread.java:136)android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2179)在android.os.Looper.loop(Looper.java:143)的android.app.ActivityThread.main(ActivityThread.java:5068),位于java.lang.reflect的java.lang.reflect.Method.invokeNative(Native Method) .Method.invoke(Method.java:521)位于com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:858)com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) )at dalvik.system.NativeStart.main(Native Method)引起:android.database.sqlite.SQLiteException:没有这样的表:LISTE :,编译时:从android.database.sqli的LISTE中选择_id 位于android.database.sqlite.SQLiteCompiledSql的android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)中的te.SQLiteCompiledSql.native_compile(Native Method).(androiditeCompiledSql.java:64)android.database.sqlite.SQLiteProgram (SQLiteProgram.java:80)位于android.database.sqlite.SQLiteDatabase的android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:46)android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53).在android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1387)的rawQueryWithFactory(SQLiteDatabase.java:1417)... 11更多

我的应用程序创建数据库,但它不复制资产文件夹的文件表data\data\packagename\databases\mydatabase.

我的代码:

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();

}
Run Code Online (Sandbox Code Playgroud)

我认为这个copydatabase功能有问题,但我没有看到.

此代码适用于除HTC DESIRE HD v2.2.1 1.72.405.3之外的所有设备.

HTC Desire上面给出的版本可能存在哪些问题?如何解决这个问题?

Squ*_*onk 0

这只是一个猜测,意味着 Desire HD 的 Android 版本存在一个“错误”,所以我可能会非常失望。

我想知道那个版本的 Android 是否没有在它应该创建的地方创建数据库。您假设 DB_PATH 通常是 \data\data\packagename\databases\ 但如果不是怎么办?结果如下...

  1. this.getReadableDatabase()将在 \some\in Correct\path\mydatabase 创建一个空数据库
  2. 使用new FileOutputStream(outFileName) 只是创建一个新的空二进制文件,因为上面没有在您期望的位置创建数据库。
  3. 复制成功
  4. getReadableDatabase()在执行 SELECT 请求之前,使用或请求访问数据库,getWriteableDatabase()但这两者都只会打开在步骤 1 中创建的空数据库。

简而言之,复制过程很可能工作正常,但正在操作的数据库是空的,并且位于与您期望的位置不同的位置。

只是一个想法(多年来我见过类似的事情发生)。

  • 您好,感谢我的应用程序的用户,我找到了解决方案。这里是解决方案:[http://www.anddev.org/networking-database-problems-f29/missing-table-in-sqlite-with-specific-version-of-desire-hd-t50364.html][1] [1]:http://www.anddev.org/networking-database-problems-f29/missing-table-in-sqlite-with-specific-version-of-desire-hd-t50364.html (2认同)