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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:48:21+00:00 2026-05-28T15:48:21+00:00

I looked at other questions regarding this problem and tried their solutions, but it

  • 0

I looked at other questions regarding this problem and tried their solutions, but it did not help me unfortunately.

The problem is not of critical nature, meaning my program does not crash, it continues running, but anyway I would like not to have errors if possible.

I am using AsyncTask class to create some objects and load them up into an array. Database I use is a file obtained from the net, therefore I have no DBhelper class. I open the DB inside of doInBackround of AsyncTask. Inside it I have try-catch where I do all my db related work.

At first I had variables for db and cursors inside of the try statement and also I had closure of db and cursors in it at the end. I found one link saying try-catch-final should be used, so I did that, I moved variable declaration outsite of try-catch-final statement and managed closing of db and cursor variables in the final part, but still it does not help, errors are still here.

Here are some errors, I won’t C/P all of them:

01-25 17:22:45.142: E/Database(333): close() was never explicitly called on database ‘/data/data/stet.cityapp/app_databases/baza.db

01-25 17:22:45.142: E/Database(333): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here

01-25 17:22:45.142: E/Database(333): at stetocina.cityapp.SplashScreen$LoadDB.doInBackground(SplashScreen.java:1)

01-25 17:22:45.142: E/Database(333): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)

01-25 17:22:45.142: E/Database(333): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)

Outline of the code:

protected Boolean doInBackground(String... params) {
SQLiteDatabase db = null;
Cursor poisCursor = null, tmpCursor = null;
String whereString;
try {               
    String DBpath = getDir("databases", 0).getAbsolutePath() + File.separator + "baza.db";
    if (SQLiteDatabase.openDatabase(DBpath, null, SQLiteDatabase.OPEN_READONLY) == null) return false;
    db =  SQLiteDatabase.openDatabase(DBpath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
    
    ...
    
    result = true;
} catch (Exception e) {
    result = false;
    return result;
} finally {
    if (!poisCursor.isClosed() || poisCursor != null) {
        poisCursor.deactivate();
        poisCursor.close();
        poisCursor = null;
    }
    if (!db.isOpen() || db != null) {
        db.close();
        db = null;
    }
}
return result;

}

Could there be some problem that I am doing it in an AsyncTask? In the onPostExecute methond of AsyncTaks, if everything went well and result is true, I open a new Activity, and while debugging I noticed that the error is displayed only when new activity is displayed and not immediatelly after exit from doInBackground.

Thanks for the help!

  • 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-28T15:48:21+00:00Added an answer on May 28, 2026 at 3:48 pm

    Isn’t the database being opened twice?

    1. inside the ‘if’ condition (if (SQLiteDatabase.openDatabase(DBpath, null, SQLiteDatabase.OPEN_READONLY) == null) return false;)

    2. in the next line (db = SQLiteDatabase.openDatabase(DBpath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);)

    and you are closing only the second one(db).

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

Sidebar

Related Questions

I have looked at other questions regarding this problem but the solutions don't work
I have looked at other questions and answers regarding this, but can't seem to
I have looked at the other questions related to this problem but I do
I've looked at other questions on Stack Overflow related to this question, but none
I've looked through several other questions here and on other sites regarding this issue,
I know there are other questions regarding this subject, and I've looked at this
I looked through other StackOverFlow questions, but I'm a little confused. I'm trying to
Just to make this clear, I have looked at the other questions on this
I've looked at several other SGen-related questions on here and either their answers don't
I have looked for similar questions, but could find none other than the difference

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.