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 8775993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:56:35+00:00 2026-06-13T18:56:35+00:00

In my Android Activity I need to read things from a database. I’ve created

  • 0

In my Android Activity I need to read things from a database. I’ve created a helper class which deals with my database access. This helper class has several different methods designed to read different things and return them without much fuss. Here is one example.

public String GetName(int id)
{
    String toReturn = null;
    Cursor cursor = null;

    try
    {
        cursor = db.query(TABLE_NAME,
            new String[] {"name"},
            "id = " + id,
            null,
            null,
            null,
            null,
            null);

        assert(cursor.getCount() == 1);

        cursor.moveToFirst();

        toReturn = new String(cursor.getString(0)); 
    }
    finally
    {
        if(cursor != null)
            cursor.close();
    }

    return toReturn;
}

I keep getting the error

10-10 15:52:18.991: W/SQLiteCompiledSql(28313): Releasing statement in a finalizer. Please ensure that you explicitly call close() on your cursor: SELECT name FROM my_table WHERE id = 0
10-10 15:52:18.991: W/SQLiteCompiledSql(28313): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here

with a stack trace that leads right to this function (and ones very similar to it), although the Activity works fine. What am I doing wrong? I looked around here for a while, and that’s when I added the try/finally to make sure I always close the Cursor, but I’m still getting the error. How can I fix this?

  • 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-06-13T18:56:37+00:00Added an answer on June 13, 2026 at 6:56 pm

    You are closing cursor correctly but you also need to close the database, make sure that you are closing the database also:

    if(db.isOpen()) db.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed some reusable android component which is basically a class . This
In my Android Activity, I need to add a single View dynamically (at runtime),
I need to get an unique id of an android activity instance. I'd like
I am developing an android application where in each activity i need to pass
I need to develop an android app that achieves the following: Create an activity
I need to perform action, when my activity is fully loaded? Does Android have
I have an android activity that downloads content from the web. The activity have
I read the link at http://developer.android.com/resources/articles/avoiding-memory-leaks.html and need to know what should be done
i need to write simple android application that run on the background and read
i need to read the proxy information from the phone and if the phone

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.