我的應用程序在資產文件夾中有一個SQLite數據庫。當用戶啓動我的應用程序時,數據庫被創建並且表也是如此。在特定版本的HTC DESIRE HD SQLite中缺少表格
能正常工作有很多的設備(Nexus One的,HTC Magic的,SGS,X10 ......甚至HTC渴望HD V2.2)。 我的應用程序適用於所有版本的Android(在我的設備上測試過(1.6,2.2,2.2.1Htc Magic)和仿真器(v1.5直到v2.3)
我只是有一個問題HTC DESIRE HD V2.2.1 1.72.405.3
的logcat的:
android.database.sqlite.SQLiteException:沒有這樣的表:名單:,在編譯:從LISTE 在Android的選擇_id。 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) 在dalvik.system.NativeStart.main(本機方法) 引起:android.database.sqlite.SQLiteException:沒有這樣的表:LISTE:,編譯時:從android.database.sqlite.database.sqlite.SQLiteCompiledSql android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) LISTE (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) 在android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53) 在android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1417) 在機器人。 database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1387) ... 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();
}
我認爲copydatabase
功能有問題,但我沒有看到。
此代碼工作正常,除了HTC DESIRE HD V2.2.1 1.72.405.3所有設備。
可能存在什麼樣的問題在這裏與上述指定版本的HTC Desire?這怎麼解決?
您發佈的代碼涉及創建數據庫。你的錯誤處理數據庫中一個表的SELECT **語句。 – 2011-01-11 21:52:19
是的,我的錯誤處理SELECT語句,因爲我的數據庫是在用戶發出他的第一個sql請求時創建的。數據庫已創建但不是LISTE表,因此SELECT語句錯誤 – William 2011-01-11 22:03:56