Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:38:28+00:00 2026-05-25T12:38:28+00:00

I have a list view populated by an adapter reading from SQLite database. When

  • 0

I have a list view populated by an adapter reading from SQLite database. When I scroll down in the list on screen I get the following error. I also get the same error when switching to another tab in the application (it is a tab based app).

close() was never explicitly called on database
DatabaseNotClosedException : Application did not close the cursor or database object that was opened here.

Does anyone know why this is happening ? I have posted the main and adapter class files below.

Main Class :

public class Home extends ListActivity {

private DataBaseHelper myDbHelper;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.homeaz);

    ListView yourList = (ListView) findViewById(android.R.id.list);

    yourList.setOnItemClickListener(new OnItemClickListener()

    {
                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

                        Log.e("onClick",""+arg3);
                        Intent i = new Intent(Home.this,DetailView.class);
                        i.putExtra(DataBaseHelper.ID, arg3);
                        // Activity returns an result if called with startActivityForResult

                        /**Home.this.finish();*/
                        startActivity(i);

                        }   
    });


    myDbHelper = new DataBaseHelper(this);

    try {

        myDbHelper.createDataBase();

} catch (IOException ioe) {

    throw new Error("Unable to create database");

}

try {

    myDbHelper.openDataBase();

}catch(SQLException sqle){

    throw sqle;

}

try {

    Cursor cursor = getPlaces();
    showPlaces(cursor);

}

finally {

myDbHelper.close();

}
}

private static String ORDER_BY = NAME + " ASC";

private Cursor getPlaces() {

    SQLiteDatabase db = myDbHelper.getReadableDatabase();
    Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, ORDER_BY);
    startManagingCursor(cursor);
    return cursor;

}

private void showPlaces(Cursor cursor) {

    MyCustomAdapterClass adapter = new MyCustomAdapterClass(this,cursor, true); setListAdapter(adapter); 

}

Adapter Class :

public class MyCustomAdapterClass extends CursorAdapter {

public MyCustomAdapterClass(Context context, Cursor c, boolean autoRequery) {
    super(context, c, autoRequery);
    // TODO Auto-generated constructor stub
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.item, parent, false);
}

@Override

public void bindView(View view, Context context, Cursor cursor) {
((TextView) view.findViewById(R.id.name)).setText(cursor.getString(cursor.getColumnIndex("Name")));
((TextView) view.findViewById(R.id.description)).setText(cursor.getString(cursor.getColumnIndex("Area")));
((TextView) view.findViewById(R.id.address)).setText(cursor.getString(cursor.getColumnIndex("AddressLine1")));
switch (cursor.getInt(cursor.getColumnIndex("_id"))) {
case 1:
((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture1);
break;
case 2:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture2);
break;
case 3:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture3);
break;
case 4:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture4);
break;
case 5:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture5);
break;
case 6:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture6);
break;
case 7:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture7);
break;
case 8:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture8);
break;
case 9:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture9);
break;
case 10:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture10);
break;
case 11:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture11);
break;
case 12:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture12);
break;
case 13:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture13);
break;
case 14:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture14);
break;
case 15:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture15);
break;
case 16:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture16);
break;
case 17:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture17);
break;
case 18:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture18);
break;
case 19:
    ((ImageView) view.findViewById(R.id.Logo)).setImageResource(R.drawable.picture19);
break;
case 20:

Log :

09-10 18:44:25.495: INFO/ActivityManager(59): Starting activity: Intent { cmp=com.Beutelkind.Database/.DetailView (has extras) }
09-10 18:44:25.665: DEBUG/dalvikvm(415): GC_EXTERNAL_ALLOC freed 4966 objects / 284992 bytes in 66ms
09-10 18:44:26.284: DEBUG/dalvikvm(415): GC_EXTERNAL_ALLOC freed 300 objects / 14840 bytes in 56ms
09-10 18:44:27.435: INFO/ActivityManager(59): Displayed activity com.Beutelkind.Database/.DetailView: 1888 ms (total 1888 ms)
09-10 18:44:28.725: INFO/ActivityManager(59): Starting activity: Intent { cmp=com.Beutelkind.Database/.Main }
09-10 18:44:28.825: INFO/Database(415): sqlite returned: error code = 14, msg = cannot open file at source line 25467
09-10 18:44:28.825: ERROR/Database(415): sqlite3_open_v2(“/mnt/sdcard/DatabaseC.sqlite”, &handle, 1, NULL) failed
09-10 18:44:29.535: INFO/ActivityManager(59): Displayed activity com.Beutelkind.Database/.Main: 781 ms (total 781 ms)
09-10 18:44:32.405: DEBUG/dalvikvm(415): GC_EXTERNAL_ALLOC freed 2748 objects / 167024 bytes in 63ms
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): Releasing statement in a finalizer. Please ensure that you explicitly call close() on your cursor: SELECT DISTINCT _id, Name, Description, Area, Postcode, AddressLine1, OpeningTimes, NearestTube, Cos
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:62)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:80)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:46)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at com.Beutelkind.Database.DetailView.populateFields(DetailView.java:79)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at com.Beutelkind.Database.DetailView.onCreate(DetailView.java:70)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.os.Looper.loop(Looper.java:123)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 18:44:32.455: WARN/SQLiteCompiledSql(415): at dalvik.system.NativeStart.main(Native Method)
09-10 18:44:32.475: ERROR/Database(415): close() was never explicitly called on database ‘/data/data/com.Beutelkind.Database/databases/DatabaseC.sqlite’
09-10 18:44:32.475: ERROR/Database(415): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
09-10 18:44:32.475: ERROR/Database(415): at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1810)
09-10 18:44:32.475: ERROR/Database(415): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
09-10 18:44:32.475: ERROR/Database(415): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
09-10 18:44:32.475: ERROR/Database(415): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844)
09-10 18:44:32.475: ERROR/Database(415): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540)
09-10 18:44:32.475: ERROR/Database(415): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
09-10 18:44:32.475: ERROR/Database(415): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
09-10 18:44:32.475: ERROR/Database(415): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158)
09-10 18:44:32.475: ERROR/Database(415): at com.Beutelkind.Database.DetailView.populateFields(DetailView.java:77)
09-10 18:44:32.475: ERROR/Database(415): at com.Beutelkind.Database.DetailView.onCreate(DetailView.java:70)
09-10 18:44:32.475: ERROR/Database(415): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-10 18:44:32.475: ERROR/Database(415): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-10 18:44:32.475: ERROR/Database(415): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 18:44:32.475: ERROR/Database(415): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 18:44:32.475: ERROR/Database(415): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 18:44:32.475: ERROR/Database(415): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 18:44:32.475: ERROR/Database(415): at android.os.Looper.loop(Looper.java:123)
09-10 18:44:32.475: ERROR/Database(415): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 18:44:32.475: ERROR/Database(415): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 18:44:32.475: ERROR/Database(415): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 18:44:32.475: ERROR/Database(415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 18:44:32.475: ERROR/Database(415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 18:44:32.475: ERROR/Database(415): at dalvik.system.NativeStart.main(Native Method)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:38:29+00:00Added an answer on May 25, 2026 at 12:38 pm

    Easy one, you are not closing your database handles. For instance, you open a cursor in getPlaces but never close it when done using it, nor the db object from where it came.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list view which is populated via records from the database. Now
I have a list view, the contain is populated from a database. And I
I have the following XML file getting populated via list view. I can't get
i have a grid view with images populated from a list. when i remove
I have a listview that's populated by rows that get their data from a
I have a top list view in my current iPhone app, that's populated by
I have used a custom array adapter to populate my list view.The problem i
I have two activities. In activity1 , I have list view which is populated
I have created a custom Base Adapter class, to populate a list view with
I have a list view control which at the moment only allows one item

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.