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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:06:43+00:00 2026-06-04T07:06:43+00:00

I have an app that functions properly and does not force close or crash.

  • 0

I have an app that functions properly and does not force close or crash. But when I look at LogCat, it occasionally gives me this:

05-20 15:24:55.338: E/SQLiteDatabase(12707): close() was never explicitly called on database '/data/data/com.---.--/databases/debt.db' 
05-20 15:24:55.338: E/SQLiteDatabase(12707): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here

a little ways down…

05-20 15:24:55.338: E/System(12707): Uncaught exception thrown by finalizer
05-20 15:24:55.338: E/System(12707): java.lang.IllegalStateException: Don't have database lock!

I am not sure when I should be opening and closing my Database?

I have a Main activity that is simply a splash screen. It then goes into an activity that calls a ListView using info from the DB; so it is at this activity where the DB is first opened.

There is also one other Activity where the DB is required that branches off the one with the ListVeew. When am I supposed to be opening and closing this? Word seems to be that I simply need to open once, and then close when the app is “paused”, “stopped” or “destroyed”.

If this is the case, where do I put the db.close() method… in the Splash Screen Main Activity where onStop, etc is located? or the same Activity as the one that opens the DB? or.. is there another place?

UPDATE:

This is the line in code that the error keeps pointing to:

public void open() throws SQLException {
    database = dbHelper.getWritableDatabase();
}
  • 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-04T07:06:44+00:00Added an answer on June 4, 2026 at 7:06 am

    If you’re using an instance of a DatabaseHelper class, and after you initialize the DBHelper object, every time you do work in the database you should call the open method before you do work, then create a new cursor, query the database, do work with the information you just stored in the cursor, when you’re done close the cursor, then close the database. For example if you wanted to grab every item in a database you would do something like :

    ...    
    DataBaseHelper db = new DataBaseHelper(this);
    ... 
    db.open();
    Cursor cursor = db.getAllItems(); 
    maxCount = cursor.getCount(); 
    Random gen = new Random();
    row = gen.nextInt(maxCount); // Generate random between 0 and max
    if (cursor.moveToPosition(row)) {
        String myString = cursor.getString(1);  //here I want the second column
        displayString(myString); //private method
    }
    cursor.close();
    db.close(); 
    

    getAllItems is a public method in my DatabaseHelper, it looks like this in case you were wondering

    public Cursor getAllItems() {
        return db.query(DATABASE_TABLE, 
            new String[] {
                KEY_ROWID, 
                KEY_NAME
            }, 
            null, 
            null, 
            null, 
            null, 
            null);
    }
    

    This is how I access my database and I haven’t gotten any of the errors you’ve got, and it works perfectly.

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

Sidebar

Related Questions

have an app that finds your GPS location successfully, but I need to be
i have an app that sends out email but i have to only send
Have an app that has listings - think classified ads - and each listing
I have an app that needs to read a PDF file from the file
We have an app that needs to access network resources. It's written in VB.Net.
I have an app that is run from a compiled DLL on a web
I have an app that sends multiple Ajax requests simultaneously. I was originally running
I have an app that has a centre view with two views off to
I have an app that needs to be able use either an sqlite3 datebase
I have an app that shows a series of UIImageView s on a ScrollView

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.