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

  • SEARCH
  • Home
  • 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 4020874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:16:56+00:00 2026-05-20T10:16:56+00:00

I get this error after going to this activity, starting a new one, coming

  • 0

I get this error after going to this activity, starting a new one, coming back. It doesn’t happen when I first load the activity. functionally everything works… but I still get this error.

ERROR/Cursor(1059): Finalizing a
Cursor that has not been deactivated
or closed. database =
/data/data/com.roger.testapp/databases/data,
table = null, query = SELECT MAX(_id)
FROM record

03-02 16:47:21.835:
ERROR/Cursor(1059):
android.database.sqlite.DatabaseObjectNotClosedException:
Application did not close the cursor
or database object that was opened
here

In onCreate:

    mDbHelper = new CommonDbAdapter(this);
    mDbHelper.open();
    fillData();

fillData() calls fetchNote in my dbhelper, the cursor is used for a couple things, if rowId == 0, that means I didn’t select an item to get into this activity and I want to get the last row in that table. if rowId = something else, then I grab that row. I think the problem is in here somewhere, I’m just not sure.

public Cursor fetchNote(long rowId, String table, String columns) throws SQLException {
    if (rowId == 0) {
        String query = "SELECT MAX(_id) FROM record";
        Cursor cursor = mDb.rawQuery(query, null);
        rowId = 0;     
        if (cursor.moveToFirst())
        {               
          rowId = cursor.getInt(0);                         
        }
    }
    Cursor mCursor =
        mDb.query(true, table, new String[] {KEY_ROWID,
                columns}, KEY_ROWID + "=" + rowId, null,
                null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;

}

In onDestroy:

super.onDestroy();
    if (mDbHelper != null) {
        mDbHelper.close();
    }

Also, I am startManagingCursor

  • 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-20T10:16:57+00:00Added an answer on May 20, 2026 at 10:16 am

    Don’t close your database in onDestroy. Close it immediately after you’re done using it(make sure every cursor is closed before the database is closed). onDestroy may not be called when you expect.

    Also, close your Cursor object after you’re done using it.

    Edits:
    Since your activity is managing your Cursor, you may consider stop managing it and closing everything in the onPause method, and in onResume open everything up and fillData once again. If you could change your code around so you dont rely on your activity managing the cursor, you wouldn’t need to hold into open database objects and worry about them.

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

Sidebar

Related Questions

Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
I get this error when trying to load a Zend Framework application: Fatal error:
I get this 'error' when running PEVerify on a custom generated assembly. [MD](0x8013124C): Error:
I get this error when trying ruby script/console Rails requires RubyGems >= . Please
I get this error message in Eclipse: Access restriction: The type DirectoryWalker is not
I get this error when I run a django app ( dpaste ) Template
I get this error when I try to use time_ago_in_words : Comparison of String
I get this error when trying to link a win32 exe project. I have
I get this error when launching my Mongrel server... $ script/server --debugger => Booting
I get this error when compiling a C# application. Looks like a trivial error,

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.