La mia applicazione ha un database SQLite nella cartella delle risorse. Quando l'utente avvia la mia applicazione, vengono creati anche il database e anche le tabelle.tabella mancante in SQLite con versione specifica di HTC DESIRE HD
Questo funziona perfettamente con molti dispositivi (Nexus One, Htc Magic, SGS, X10 ... e persino Htc Desire HD v2.2). La mia applicazione funziona con tutte le versioni di Android (testato sul mio dispositivo (1.6, 2.2, 2.2.1 HTC Magic) e sull'emulatore (v1,5 fino v2.3).
Ho solo un problema con HTC DESIRE HD v2.2.1 1.72.405.3
Il logcat:.
android.database.sqlite.SQLiteException: tale tabella: LISTE:, durante la compilazione: selezionare _id da LISTE a Android. app.ActivityThread.performLaunchActivity (ActivityThread.java:2833) su android.app.ActivityThread .handleLaunchActivity (ActivityThread.java:2854) su android.app.ActivityThread.access $ 2300 (ActivityThread.java:136) su android.app.ActivityThread $ H.handleMessage (ActivityThread.java:2179) su android.os. Handler.dispatchMessage (Handler.java:99) su android.os.Looper.loop (Looper.java:143) su android.app.ActivityThread.main (ActivityThread.java:5068) su java.lang.reflect. Method.invokeNative (metodo natale) a java.lang.reflect.Method.invoke (Method.java:521) a com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:858) a com .android.internal.os.ZygoteInit.main (ZygoteInit.java:616) in dalvik.system.NativeStart.main (metodo nativo) Causato da: android.database.sqlite.SQLiteException: nessuna tabella: LISTE:, durante la compilazione: selezionare _id da LISTE su android.database.sqlite.SQLiteCompiledSql.native_compile (Metodo nativo) su android.database.sqlite.SQLiteCompiledSql .compile (SQLiteCompiledSql.java:91) su android.database.sqlite.SQLiteCompiledSql. (SQLiteCompiledSql.java:64) su android.database.sqlite.SQLiteProgram. (SQLiteProgram.java:80) su android.database.sqlite .SQLiteQuery. (SQLiteQuery.java:46) a android.database.sqlite.SQLiteDirectCursorDriver.query (SQLiteDirectCursorDriver.java:53) a android.database.sqlite.SQLiteDatabase.rawQueryWithFactory (SQLiteDatabase.java:1417) a Android. database.sqlite.SQLiteDatabase.rawQuery (SQLiteDatabase.java:1387) ... 11 more
mia applicazione creare il database, ma non copia le tabelle del file della cartella di asset in data\data\packagename\databases\mydatabase
.
Il mio codice:
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();
}
Penso che la funzione copydatabase
ha un problema, ma non vedo.
Questo codice funziona correttamente con tutti i dispositivi tranne lo HTC DESIRE HD v2.2.1 1.72.405.3.
Quali problemi possono esistere qui per l'HTC Desire con la versione indicata sopra? Come si può rimediare?
Il codice postato riguarda la creazione di un database. Il tuo errore riguarda un'istruzione ** SELECT ** da una tabella all'interno del tuo database. –
Sì, il mio errore riguarda un'istruzione SELECT perché il mio database viene creato quando l'utente effettua la sua prima richiesta sql. Il database viene creato ma non la tabella LISTE ad esempio, quindi l'errore dell'istruzione SELECT – William