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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:40:23+00:00 2026-05-26T04:40:23+00:00

Android-newbie playing around with a SimpleCursorAdapter and I’ve run into a few problems that

  • 0

Android-newbie playing around with a SimpleCursorAdapter and I’ve run into a few problems that I’m unable to solve.

This is the code (imports omitted):

package se.ribit.bb;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class CountyBrowser extends Activity {
  private AVApplication audiovideo;
  private final String LOG_TAG = AVApplication.LOG_TAG;
  private final String TAG = "=== " + CountyBrowser.class.getSimpleName() + ": ";

  static final String[] FROM = { LocationDB.C_NAME};
  static final int[]    TO   = { R.id.locationName };

  //  DB dbHelper;
  private Cursor cursor;
  private ListView listItems;
  private SimpleCursorAdapter adapter;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(LOG_TAG, TAG + "onCreate");

    setContentView(R.layout.county_main_view);

    // View for the adapter 
    listItems = (ListView) findViewById(R.id.county_listview);

    // Get the application context
    audiovideo = (AVApplication) getApplication();

    audiovideo.httpCommand(Commands.GET_COUNTIES, null);
  }

  @Override
  protected void onResume() {
    super.onResume();

    showCounties();
  }

  public void showCounties() {
    Log.d(LOG_TAG, TAG + "refreshItemsList();");

    // Get a cursor with all item updates
    cursor = audiovideo.getLocationDB().getCounties();
    startManagingCursor(cursor);

    // Setup the adapter
    adapter = new SimpleCursorAdapter(this, R.layout.county_listview_item, cursor, FROM, TO);

    listItems.setAdapter(adapter);
    listItems.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        int countyID = cursor.getInt(cursor.getColumnIndex(LocationDB.C_ID));
        String countyName = cursor.getString(cursor.getColumnIndex(LocationDB.C_NAME));
        String foo = String.format(TAG + "Clicked ID #%d (%s)", countyID, countyName);
        Log.i(LOG_TAG, foo);

        // Show the item in a new activity
        Intent apan = new Intent(audiovideo, MunicipalBrowser.class);
        apan.putExtra("countyID", countyID);
        startActivity(apan);
      }
    });
  } // refreshItemsList
}

I.e: This opens a listview and fills it with a bunch of county-names around my area. When clicking a county, another activity (with almost identical code) is launched, showing the municipals in the county.

The code works, mostly. Every now and then these lines pops up in LogView (one set for each listview-cell):

10-11 09:28:06.601: INFO/dalvikvm(244): Uncaught exception thrown by finalizer (will be discarded):
10-11 09:28:06.641: INFO/dalvikvm(244): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@44c7e808 on null that has not been deactivated \

or closed
10-11 09:28:06.651: INFO/dalvikvm(244): at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
10-11 09:28:06.651: INFO/dalvikvm(244): at dalvik.system.NativeStart.run(Native Method)

I don’t understand why I get these, but since the emulator doesn’t crash I didn’t bother too much.

Now for the critical error: When my listview is launched and I don’t click any of the cells for some amount of time (maybe 5 minutes), and then click, the emulator crashes hard and outputs this in LogCat:

10-11 11:45:22.591: ERROR/AndroidRuntime(255): Uncaught handler: thread main exiting due to uncaught exception
10-11 11:45:22.682: ERROR/AndroidRuntime(255): java.lang.RuntimeException: Unable to start activity ComponentInfo{se.ribit.bb/se.ribit.bb.TownBrowser}: android.database.sqlite.SQLiteException: Unable to close due to unfinalised statements
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.os.Looper.loop(Looper.java:123)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.app.ActivityThread.main(ActivityThread.java:4363)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at java.lang.reflect.Method.invokeNative(Native Method)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at java.lang.reflect.Method.invoke(Method.java:521)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at dalvik.system.NativeStart.main(Native Method)
10-11 11:45:22.682: ERROR/AndroidRuntime(255): Caused by: android.database.sqlite.SQLiteException: Unable to close due to unfinalised statements
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.database.sqlite.SQLiteDatabase.dbclose(Native Method)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:254)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.database.sqlite.SQLiteClosable.releaseReference(SQLiteClosable.java:42)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.database.sqlite.SQLiteProgram.onAllReferencesReleasedFromContainer(SQLiteProgram.java:76)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.database.sqlite.SQLiteDatabase.closeClosable(SQLiteDatabase.java:799)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.database.sqlite.SQLiteDatabase.close(SQLiteDatabase.java:786)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at se.ribit.bb.LocationDB.updateTowns(LocationDB.java:291)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at se.ribit.bb.AVApplication.httpCommand(AVApplication.java:217)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at se.ribit.bb.TownBrowser.onCreate(TownBrowser.java:44)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
10-11 11:45:22.682: ERROR/AndroidRuntime(255):     ... 11 more

Can anyone tell me what’s going on here?

  • 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-26T04:40:24+00:00Added an answer on May 26, 2026 at 4:40 am

    It’s hard to know without seeing code, but you are probably closing the database before closing the cursor: SQLite Exception in android

    This is where the error is, so you should inspect there: at se.ribit.bb.LocationDB.updateTowns(LocationDB.java:291)

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

Sidebar

Related Questions

In answering this question please take into consideration the fact that I'm an Android
I am a newbie to Android and playing around with the UI and SQLLite
I am an android newbie so forgive me if this question is simple. Basically
I am newbie in android. I developed an android application that shows 15 tabs.
I have the following code that creates my table. I insert data into it
Forgive me if this is a newbie question, but... When playing video, is it
I'm an Android newbie so I apologize if this is a dumb question .
My Google-Fu is failing this Android newbie today. Does anybody know of a good
Being an Android newbie experimenting with GPS stuff I managed to put together this
I am android newbie. I made a simple program, and I used Toast code

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.