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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:55:57+00:00 2026-06-19T01:55:57+00:00

I have a SQLite db that displays a high scores table. I want to

  • 0

I have a SQLite db that displays a high scores table. I want to give the user the option to delete the high scores if they want (see screenshot below). If the user selects Yes, I want the dialog to close and then the screen behind the dialog to be empty except for the 4 column headers, 2 buttons and the activity header.

Right now, when the user selects Yes it gives the below LogCat.

02-20 09:59:39.686: E/AndroidRuntime(2458): FATAL EXCEPTION: main
02-20 09:59:39.686: E/AndroidRuntime(2458): java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/matt.lyons.bibletrivia/databases/test3
02-20 09:59:39.686: E/AndroidRuntime(2458):     at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1489)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at matt.lyons.bibletrivia.DatabaseHelper.deleteAll(DatabaseHelper.java:46)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at matt.lyons.bibletrivia.Highscores$3.onClick(Highscores.java:198)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at android.view.View.performClick(View.java:4202)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at android.view.View$PerformClick.run(View.java:17340)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at android.os.Handler.handleCallback(Handler.java:725)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at android.os.Looper.loop(Looper.java:137)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at android.app.ActivityThread.main(ActivityThread.java:5039)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at java.lang.reflect.Method.invokeNative(Native Method)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at java.lang.reflect.Method.invoke(Method.java:511)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-20 09:59:39.686: E/AndroidRuntime(2458):     at dalvik.system.NativeStart.main(Native Method)

DatabaseHelper.java

//Delete all rows/whole table from high scores.
public int deleteAll() { 
    return db.delete(TABLE, null, null);  //Line 46
}

Highscores.java

public void areYouSure() {

    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.clearhighscores);
    dialog.setTitle("Clear Highscores?");

    TextView question = (TextView)dialog.findViewById(R.id.question);
    Button yes = (Button)dialog.findViewById(R.id.yes);
    Button no = (Button)dialog.findViewById(R.id.no);

    question.setText("This is not reversable.  Are you sure you want to delete the high scores?");
    yes.setText("Yes");
    no.setText("No");

    yes.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            dh.deleteAll();  //Line 198
            dialog.dismiss();


        }
    });

    no.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            dialog.dismiss();
        }
    });
    dialog.show();
}

enter image description here

My question is how to let the user delete the db without the program crashing.

  • 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-19T01:55:58+00:00Added an answer on June 19, 2026 at 1:55 am

    java.lang.IllegalStateException: attempt to re-open an already-closed
    object: SQLiteDatabase

    It means that you trying to delete data but your database is closed. So before delete you need to check if db is open and if not, open it else just perform delete operation.

    Where you closing db? You should close any datasources, cursor etc. in onDestroy() or onStop() method.

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

Sidebar

Related Questions

I have an iOS app that displays content from a sqlite db in a
I have an SQLite database table which contains user selected favorite items. I would
I have a Sqlite database that has a table consisting of company information (Companies)
I have a uitableview that is populated from a sqlite query. I want to
I have a Table in SQLite like the following I want to display it
I have a sqlite table that has amount field with NUMERIC(10,5) value(I know data
I have a SQLite query that returns a Cursor . I want to add
Let's say I have an SQLite table that contains 10 columns of type text(20).
I have a SQLite database that contains a huge set of log messages. I
I have a SQLite DB that has people LastName, FirstName, Department and I need

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.