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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:16:47+00:00 2026-06-01T06:16:47+00:00

I am accessing data from sqlite data base in my following code. @Override public

  • 0

I am accessing data from sqlite data base in my following code.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.profile);
    type_spn = (Spinner) findViewById(R.id.type_spn);
    animal_spn = (Spinner) findViewById(R.id.animal_spn);
    habitat_txt=(TextView)findViewById(R.id.life_txt);
    diet_txt=(TextView)findViewById(R.id.habit_txt);
    discription_txt=(TextView)findViewById(R.id.description_txt);

    adb = DBAdpter.getAdapterInstance(SecondActivity.this);
    adb.createdatabase();
    db = adb.openDataBase();

    cr = db.rawQuery("select distinct type from zoo", new String[] {});

    if (cr.getCount() > 0) {
        cr.moveToFirst();
        for (int i = 0; i < cr.getCount(); i++) {
            String type = cr.getString(0);
            cr.moveToNext();
            type_list.add(type);
        }
        db.close();
        ArrayAdapter<String> type_add = new ArrayAdapter<String>(
                SecondActivity.this, R.layout.spinnerlayout, type_list);
        type_spn.setAdapter(type_add);

    }

    type_spn.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            animal_list.clear();
            String type_name = arg0.getItemAtPosition(arg2).toString();
            db = adb.openDataBase();
            cr = db.rawQuery("select animal from zoo where type like '"
                    + type_name + "%'", new String[] {});

            if (cr.getCount() > 0) {
                cr.moveToFirst();
                for (int i = 0; i < cr.getCount(); i++) {
                    String type = cr.getString(0);
                    cr.moveToNext();
                    animal_list.add(type);
                }
            }
            db.close();
            ArrayAdapter<String> type_add = new ArrayAdapter<String>(
                    SecondActivity.this, R.layout.spinnerlayout,
                    animal_list);
            animal_spn.setAdapter(type_add);

        }

        public void onNothingSelected(AdapterView<?> arg0) {

        }
    });

    animal_spn.setOnItemSelectedListener(new OnItemSelectedListener() {
        String habitat;
        String diet;
        String description;

        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            String animal_name = arg0.getItemAtPosition(arg2).toString();

            db = adb.openDataBase();
            cr = db.rawQuery(
                    "select habitat,diet,discription from zoo where type like '"
                            + animal_name + "%'", new String[] {});

            if (cr.getCount() > 0) {
                Log.v("anim","Test"+cr.getCount());
                cr.moveToFirst();
                 habitat =cr.getString(0);
                 diet =cr.getString(1);
                 description =cr.getString(2);
            }
            db.close();
            Log.v("anim","Test"+" : "+habitat+" : "+diet+" : " + description);
            habitat_txt.setText(habitat);
            diet_txt.setText(diet);
            discription_txt.setText(description);

        }

        public void onNothingSelected(AdapterView<?> arg0) {

        }
    });
}

and I am getting error like this.

03-28 18:08:09.356: ERROR/Cursor(4754): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.zoobuzz/databases/zoo_buzz.sqlite, table = null, query = select animal from zoo where type like 'Bird
03-28 18:08:09.356: ERROR/Cursor(4754): %'
03-28 18:08:09.356: ERROR/Cursor(4754): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
03-28 18:08:09.356: ERROR/Cursor(4754):     at com.zoobuzz.SecondActivity$1.onItemSelected(SecondActivity.java:65)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.widget.AdapterView.access$200(AdapterView.java:42)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:830)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.os.Handler.handleCallback(Handler.java:587)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.os.Looper.loop(Looper.java:123)
03-28 18:08:09.356: ERROR/Cursor(4754):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-28 18:08:09.356: ERROR/Cursor(4754):     at java.lang.reflect.Method.invokeNative(Native Method)
03-28 18:08:09.356: ERROR/Cursor(4754):     at java.lang.reflect.Method.invoke(Method.java:521)
03-28 18:08:09.356: ERROR/Cursor(4754):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-28 18:08:09.356: ERROR/Cursor(4754):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-28 18:08:09.356: ERROR/Cursor(4754):     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-06-01T06:16:49+00:00Added an answer on June 1, 2026 at 6:16 am

    dont open and close your database frequently db = adb.openDataBase(); instead closing database close your cursor cursor.close();

    Step:

    Database : Launcher Activity opens Database and it will remains open until the Activity gets closed. (in onDestroy() recommended)

    Cursor: When the work of cursor gets over close it.

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

Sidebar

Related Questions

I m accessing SQLite databse from the following location /data/data/files/examples/search.sqlite it works fine in
I'm fetching some data from FB using the following code: dynamic parameters = new
I am accessing this data from a web server using NSURL, what I am
I'm having an issue properly accessing an NSDictionary built from Flickr data (the flickr.photosets.getPhotos
When I am accessing an Array of data that is returned from nusoap I
I am accessing data from an SQL Server database to my ASP.Net C# based
I have have a problem loading and accessing data from a value object in
An Android/Iphone app will be accessing application data from the server. [Django-Python] How can
I want to create a socket for accessing IPv4 packets from data link layer.
I am creating an application using c# and database in webserver.while accessing data from

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.