Autore Topic: Application did not close the cursor or database object that was opened here  (Letto 652 volte)

Offline SarAndroid

  • Nuovo arrivato
  • *
  • Post: 9
  • Respect: +1
    • Mostra profilo
Ciao a tutti.
Ho un problema con il database. Premetto che non uso Java, ma Titanium Appcelerator, dunque scrivo in JavaScript e la conversione in Java avviene in runtime.
Da quando ho aggiornato l'SDK di Titanium all'ultima versione, l'applicazione continua a funzionare, ma mi è comparso un errore relativo al database. Se ho capito bene, è come se il database fosse stato aperto e non chiuso... ma io ogni volta che apro il database o un recordset lo richiudo sempre.. Esiste un modo per risalire al rigo di codice che genera l'errore? O sapreste indicarmi le cause possibili?
Vi riporto un esempio di apertura del database che eseguo in Javascript più o meno ogni volta che devo leggere i dati:
Codice (Java): [Seleziona]
// LETTURA DATI
(function(){
        //LEGGO DAL TATABASE
        myApp.DB.leggiDati = function() {      
                var db = Ti.Database.open("TestDB");
                var result = db.execute("SELECT * from tabella");              
                var elencoNomi = [];
                while(result.isValidRow()){
                        var nome = result.fieldByName("Nome")
                        elencoNomi.push(nome);
                        result.next();
                };
                result.close();
                db.close();    
                return elencoNomi;     
        };             
})();


Qui di seguito ci sono due logcat

Codice: [Seleziona]
E/Database(  436): close() was never explicitly called on database '/data/data/it.myApps.Test/databases/TestDB'
E/Database(  436): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844)
E/Database(  436):         at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540)
E/Database(  436):         at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
E/Database(  436):         at ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:72)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:134)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:267)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:160)
E/Database(  436):         at android.os.Handler.dispatchMessage(Handler.java:95)
E/Database(  436):         at android.os.Looper.loop(Looper.java:123)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104)
E/Database(  436): close() was never explicitly called on database '/data/data/it.myApps.Test/databases/TestDB'
E/Database(  436): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844)
E/Database(  436):         at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540)
E/Database(  436):         at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
E/Database(  436):         at ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:72)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:134)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:267)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:160)
E/Database(  436):         at android.os.Handler.dispatchMessage(Handler.java:95)
E/Database(  436):         at android.os.Looper.loop(Looper.java:123)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104)
E/Database(  436): close() was never explicitly called on database '/data/data/it.myApps.Test/databases/TestDB'
E/Database(  436): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844)
E/Database(  436):         at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540)
E/Database(  436):         at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
E/Database(  436):         at ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:72)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:134)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:267)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:160)
E/Database(  436):         at android.os.Handler.dispatchMessage(Handler.java:95)
E/Database(  436):         at android.os.Looper.loop(Looper.java:123)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104)
E/Database(  436): close() was never explicitly called on database '/data/data/it.myApps.Test/databases/TestDB'
E/Database(  436): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844)
E/Database(  436):         at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540)
E/Database(  436):         at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
E/Database(  436):         at ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:72)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:134)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:267)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:160)
E/Database(  436):         at android.os.Handler.dispatchMessage(Handler.java:95)
E/Database(  436):         at android.os.Looper.loop(Looper.java:123)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104)
E/Database(  436): close() was never explicitly called on database '/data/data/it.myApps.Test/databases/TestDB'
E/Database(  436): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
E/Database(  436):         at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844)
E/Database(  436):         at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540)
E/Database(  436):         at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
E/Database(  436):         at ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:72)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:134)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:267)
E/Database(  436):         at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:160)
E/Database(  436):         at android.os.Handler.dispatchMessage(Handler.java:95)
E/Database(  436):         at android.os.Looper.loop(Looper.java:123)
E/Database(  436):         at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104)


Altre volte invece mi spunta questo errore:
Codice: [Seleziona]
E/Cursor  (  436): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/it.myApps.Test/databases/TestDB, table = null, query = SELECT * FROM tabella WHERE id = 7
E/Cursor  (  436): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
E/Cursor  (  436):         at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210)
E/Cursor  (  436):         at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
E/Cursor  (  436):         at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
E/Cursor  (  436):         at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
E/Cursor  (  436):         at ti.modules.titanium.database.TiDatabaseProxy.execute(TiDatabaseProxy.java:126)
E/Cursor  (  436):         at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
E/Cursor  (  436):         at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:60)
E/Cursor  (  436):         at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:494)
E/Cursor  (  436):         at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:675)
E/Cursor  (  436):         at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:395)
E/Cursor  (  436):         at ti.modules.titanium.ui.TableViewProxy.handleMessage(TableViewProxy.java:579)
E/Cursor  (  436):         at android.os.Handler.dispatchMessage(Handler.java:95)
E/Cursor  (  436):         at android.os.Looper.loop(Looper.java:123)
E/Cursor  (  436):         at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104)

Offline bradipao

  • Moderatore globale
  • Utente storico
  • *****
  • Post: 4043
  • keep it simple
  • Respect: +567
    • Github
    • Google+
    • bradipao
    • Mostra profilo
  • Dispositivo Android:
    Nexus 5
  • Play Store ID:
    Bradipao
  • Sistema operativo:
    W7
Re:Application did not close the cursor or database object that was opened here
« Risposta #1 il: 12 Maggio 2012, 08:53:47 CEST »
0
Purtroppo non ho mai usato appcelerator, ne' ho visto farlo da altri qua sul forum. Penso che la fonte migliore di informazioni sia la community del tools stesso.
NON rispondo a domande nei messaggi privati
Bradipao @ Play Store

Offline SarAndroid

  • Nuovo arrivato
  • *
  • Post: 9
  • Respect: +1
    • Mostra profilo
Re:Application did not close the cursor or database object that was opened here
« Risposta #2 il: 19 Maggio 2012, 11:24:08 CEST »
0
Grazie lo stesso per la risposta... purtroppo non ho trovato nessuna soluzione..  :'( ma dal logcat è possibile risalire al rigo che genere un errore?

Offline EmilioCuomo

  • Nuovo arrivato
  • *
  • Post: 29
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung Galaxy Tab 10.1v
  • Sistema operativo:
    Windows
Re:Application did not close the cursor or database object that was opened here
« Risposta #3 il: 19 Maggio 2012, 23:33:50 CEST »
0
Questo errore è la mia dannazione up per te +1 chi ci aiuta

Dimenticavo io sviluppo in java

Offline SarAndroid

  • Nuovo arrivato
  • *
  • Post: 9
  • Respect: +1
    • Mostra profilo
Re:Application did not close the cursor or database object that was opened here
« Risposta #4 il: 22 Maggio 2012, 15:52:28 CEST »
0
Per quanto mi riguarda, forse ho trovato una soluzione finalmente!
Ogni volta che aprivo l'applicazione, per assicurarmi che il database venisse letto, facevo una cosa del genre:

Codice (Java): [Seleziona]
        var db = Ti.Database.open("MoneyDB");
        if(Ti.Platform.name === "android"){
                db = Ti.Database.install(Ti.Filesystem.resourcesDirectory+'/data/MyAppDB.sql', "TestDB" );             
        };
        db.execute("CREATE TABLE IF NOT EXISTS tabella (id INTEGER PRIMARY KEY, nome TEXT, cognome TEXT)");
        db.close();

Non so se in Java esiste una cosa simile ad install per caricare un database preesistente, ma di fatto, togliendo la parte relativa al metodo install l'errore non compare più, dunque così:

Codice (Java): [Seleziona]
        var db = Ti.Database.open("MoneyDB");
/*      if(Ti.Platform.name === "android"){
                db = Ti.Database.install(Ti.Filesystem.resourcesDirectory+'/data/MyAppDB.sql', "TestDB" );             
        };*/

        db.execute("CREATE TABLE IF NOT EXISTS tabella (id INTEGER PRIMARY KEY, nome TEXT, cognome TEXT)");
        db.close();