Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

application stopped in Android /SQLITE ERROR/

Yesterday the application was working normally, and i didn't edit my codes. But now its not working. the logcat is

close() was never explicitly called on database '/data/data/[myproject]/databases/MyDB' 
android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1943)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1007)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1051)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:770)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
at mn.emondo.parliament.DBAdapter.open(DBAdapter.java:46)
at mn.emondo.parliament.ProfileActivity.onCreate(ProfileActivity.java:46)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
like image 493
Saruulbat Avatar asked Mar 30 '12 08:03

Saruulbat


5 Answers

Once you open the database and cursor you must close these two before exiting from the class or activity. db.close(); cr.close();

please use this.

like image 100
praveenLal Avatar answered Nov 09 '22 14:11

praveenLal


You haven't Closed the Cursor. It is Written in your ERROR.

Application did not close the cursor or database object that was opened here

So as as i can't see your code, just check you haven't Closed your Cursor.

Or Try to Clean your Project and Re-Build it.

like image 1
Bhavin Avatar answered Nov 09 '22 13:11

Bhavin


You forgot to close() your database; the next time it is opened you'll receive a DatabaseObjectNotClosedException exception.

like image 1
Geert Avatar answered Nov 09 '22 15:11

Geert


If it was working previously and not now ,, try changing the version name of the database,,,

even after if it doesn't work , then change the version name and the database name .

like image 1
Pranav Sharma Avatar answered Nov 09 '22 13:11

Pranav Sharma


Try this method when you finish fetching data from database..
When you open database you need to call db.open() and when you finish your database work you need to call close() method. use following method.

db.close();

and you must call to open database from your Activity.java

like image 1
Sandip Armal Patil Avatar answered Nov 09 '22 15:11

Sandip Armal Patil