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 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

I get this error when debugging my ASP.NET web application after I trigger an
I get this error: Can't locate Foo.pm in @INC Is there an easier way
I get this error on an update panel within a popupControlExtender which is within
I get this error when I do an svn update : Working copy XXXXXXXX
I get this error:- You have an error in your SQL syntax; check the
We get this error in Visual Studio 2005 and TFS very often. Can anyone
i get this error {Method 'System.DateTime ConvertTimeFromUtc(System.DateTime, System.TimeZoneInfo)' has no supported translation to SQL.}
I get this error message when installing SQL 2005 Analysis services. The cabinet File
I get this error: System.Reflection.TargetException: Object does not match target type. when trying to
When I commit I get this error from Subversion: bash-2.05b$ svn commit -m testing

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.