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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:39:00+00:00 2026-05-22T14:39:00+00:00

hi all i am creating database in android ,i insert some randomly generate Integer

  • 0

hi all i am creating database in android ,i insert some randomly generate Integer in to the table and get the row from table which is match to given input. but i get attempt to acquire a reference on a close SQLiteClosable. if i use without where clause it is works. only problem is when i use where clause in query.

my code:

    db = openOrCreateDatabase("TestData.db",  SQLiteDatabase.CREATE_IF_NECESSARY, null);
    db.setVersion(1);
    db.setLocale(Locale.getDefault());
    db.setLockingEnabled(true);
    final String CREATE_TABLE_COUNTRIES ="CREATE TABLE IF NOT EXISTS tbl_countries (id INTEGER);";
    db.execSQL(CREATE_TABLE_COUNTRIES);

    ContentValues values = new ContentValues();
    values.put("id", 1);
    db.insert("tbl_countries", null, values);
    Log.e("sql", "ok");

    b1.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View view) 
        {
           String p = et.getText().toString();
           String [] columns=new String[]{"id"};    
           Cursor c=db.query("tbl_countries", columns, "id"+"=?",new String[]{p}, null, null, null);
           c.moveToFirst();
           c.close();
        }
    });

    db.close();

my log cat information

  05-23 19:02:20.880: ERROR/AndroidRuntime(5533): java.lang.IllegalStateException: attempt to acquire a reference on a close SQLiteClosable
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:31)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:56)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:49)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1236)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1123)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1081)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1158)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at com.sql.where.main$1.onClick(main.java:63)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.view.View.performClick(View.java:2364)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.view.View.onTouchEvent(View.java:4179)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.widget.TextView.onTouchEvent(TextView.java:6591)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.view.View.dispatchTouchEvent(View.java:3709)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:883)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:883)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at  android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:883)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:883)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
 05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.os.Handler.dispatchMessage(Handler.java:99)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.os.Looper.loop(Looper.java:123)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at android.app.ActivityThread.main(ActivityThread.java:4363)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at java.lang.reflect.Method.invoke(Method.java:521)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  05-23 19:02:20.880: ERROR/AndroidRuntime(5533):     at dalvik.system.NativeStart.main(Native Method)
  • 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-22T14:39:00+00:00Added an answer on May 22, 2026 at 2:39 pm

    In your onClick() method db is already closed. You should open it again or not close it, but the first is preferrable.

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

Sidebar

Related Questions

I am creating a database table that'll have a list of all Tags available
I did some research about showing the tables from my application database. all tutorials
I'm creating and app that will rely on a database, and I have all
I am creating a series of UserControls that all have some similar business logic.
When your creating a database schema and come up with all the foreign keys.
I'm creating an application for android which is a 3D inside navigation system of
I'm creating a database that's going to contain various artists which can be tagged
Using EF 4.1 Code first I wanted to stop EF creating database from Models.
I am creating a appwidget which needs to update when some changing in app's
I need to generate SQL queries with all table records, using SQL Server Management

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.