SQLite中与HTC DESIRE HD特定版本缺少表 [英] missing table in SQLite with specific version of HTC DESIRE HD

查看:103
本文介绍了SQLite中与HTC DESIRE HD特定版本缺少表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中的资源文件夹SQLite数据库。当用户启动我的应用程序,创建数据库和表了。

My application has a SQLite database in the asset folder. When the user launches my application, the database is created and the tables too.

这正常工作有很多的设备(Nexus One的,HTC Magic的,SGS,X10 ......甚至HTC渴望HD V2.2)。 我的应用程序与所有版本的Andr​​oid系统的工作原理(我的设备(1.6,2.2,2.2.1的HTC Magic上测试),并在模拟器上(v1,5至V2.3)。

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).

我只是一个 HTC DESIRE HD V2.2.1 1.72.405.3的问题。

在logcat的:

android.database.sqlite.SQLiteException:没有这样的表:名单:在编制:选择LISTE _id   在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2833)   在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2854)   在android.app.ActivityThread.access $ 2300(ActivityThread.java:136)   在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2179)   在android.os.Handler.dispatchMessage(Handler.java:99)   在android.os.Looper.loop(Looper.java:143)   在android.app.ActivityThread.main(ActivityThread.java:5068)   在java.lang.reflect.Method.invokeNative(本机方法)   在java.lang.reflect.Method.invoke(Method.java:521)   在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:858)   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)   在dalvik.system.NativeStart.main(本机方法)   致:android.database.sqlite.SQLiteException:没有这样的表:名单:在编制:从LISTE选择_id   在android.database.sqlite.SQLiteCompiledSql.native_compile(本机方法)   在android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)   在android.database.sqlite.SQLiteCompiledSql(SQLiteCompiledSql.java:64)   在android.database.sqlite.SQLiteProgram(SQLiteProgram.java:80)   在android.database.sqlite.SQLiteQuery(SQLiteQuery.java:46)   在android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)   在android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1417)   在android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1387)   ... 11个

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

我的应用程序中创建的数据库,但它不会复制的资源文件夹的文件的表格数据\数据\包名称\数据库\ MyDatabase的

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.

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

}

我觉得 copydatabase 功能有问题,但我没有看到。

I think that the copydatabase function has a problem but I don't see.

这code工作正常,除了在 HTC DESIRE HD V2.2.1 1.72.405.3的所有设备。

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

可能存在这里的的HTC Desire上面给出的版本是什么问题呢?这又如何弥补?

What problems might exist here for the HTC Desire with the given version above? How can this be remedied?

推荐答案

这是一个有点猜测,并可能意味着有一个错误在Android版本的Desire HD的,所以我可能是疯狂了。

This is a bit of a guess and would imply there is a 'bug' in that version of Android for the Desire HD so I may be wildly out.

我不知道是否该版本的Andr​​oid不会产生它应该做的数据库。你假设DB_PATH是\ DATA \数据\包名称\数据库\,因为它通常会是,但如果它是什么呢?其结果将是以下...

I'm wondering if that version of Android doesn't create the database where it should do. You're assuming that DB_PATH is \data\data\packagename\databases\ as it normally would be but what if it isn't? The result would be the following...

  1. this.getReadableDatabase()将创建一个空数据库\些\不正确\路径\ MyDatabase的
  2. 使用新 FileOutputStream中(outFileName) 简单地创建一个新的空二进制 文件,因为上面没有创造 在你期望的地方数据库。
  3. 复制成功发生
  4. 在执行SELECT请求,访问数据库的使用要求或者 getReadableDatabase() getWriteableDatabase()但无论那些只会打开在步骤1中创建的空数据库。
  1. this.getReadableDatabase() would create an empty database at \some\incorrect\path\mydatabase
  2. Using new FileOutputStream(outFileName) simply creates a new empty binary file because the above didn't create a database at the place you expect.
  3. The copy happens successfully
  4. Before performing the SELECT request, access to the database is requested using either getReadableDatabase() or getWriteableDatabase() but both of those will simply open the empty database that was created in Step 1.

总之,在复制过程很可能工作正常,但就是在被操作的数据库是空的,在不同的地方,在那里你指望了。

In short, the copy process may well have worked correctly but the DB that is being operated on is empty and in a different place to where you expect it.

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

Just an idea (I've seen similar things happen over the years).

这篇关于SQLite中与HTC DESIRE HD特定版本缺少表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆