Cursor finalize . close() issue
<p>I'm trying to retrieve the data from my database through a cursor object once the database has been queried. I seem to be getting an error on my cursor.close() and when closing my database. This has been fine up until the point but I started receiving 'cursor finalizer' errors when accessing classes from different intents.</p>

<p>At the moment I seem to have my cursor objects closing in an incorrect manner.</p>

<p>As an example heres how Im trying to retrieve all the data to populate a listview within the onCreate method of my class.</p>

<pre><code>protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


setContentView(R.layout.appointmentview);


    searchedAppView = (ListView)findViewById(android.R.id.list);

    DBHandlerApp DBAppointments = new DBHandlerApp(this, null, null);

    DBHandlerApp searchApps = new DBHandlerApp(this, null, null);

    searchApps.open();


    Cursor cursor = searchApps.getAppointmentsData();

    startManagingCursor(cursor);


    @SuppressWarnings("static-access")
    String [] from = new String [] {DBAppointments.KEY_NAMEAPP, DBAppointments.KEY_TYPEAPP, DBAppointments.KEY_TIMEAPP, DBAppointments.KEY_DATEAPP, DBAppointments.KEY_COMMENTAPP};
    int [] to = new int [] {R.id.txtAppointName, R.id.txtAppointType, R.id.txtAppointTime, R.id.txtAppointDate, R.id.txtAppointCom};

    @SuppressWarnings("deprecation")

    SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.setappointviews, cursor, from, to);
    searchedAppView.setAdapter(cursorAdapter);



    searchAppoints = (ImageButton) findViewById(R.id.btnSearchAppointName); 
    searchAppName = (EditText) findViewById(R.id.inputAppointName); 


    searchAppoints.setOnClickListener(this);

}
</code></pre>

<p>Heres the method 'getAppointmentData' of the DBHandlerApp class:</p>

<pre><code>    public Cursor getAppointmentsData() {
        String [] columns = new String[]{KEY_ROWAPPID, KEY_NAMEAPP, KEY_TYPEAPP, KEY_TIMEAPP, KEY_DATEAPP, KEY_COMMENTAPP};
        Cursor c = ourDatabase.query(DATABASE_TABLEAPP, columns, null, null, null, null, KEY_NAMEAPP + " ASC", null);

                    //*****Closing the cursor object.*****
        c.close();
        return c;
</code></pre>

<p>Logcat error:</p>

<pre><code>01-31 17:44:34.220: E/AndroidRuntime(269): FATAL EXCEPTION: main
01-31 17:44:34.220: E/AndroidRuntime(269): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.ViewAppointments}: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentsTable ORDER BY app_name ASC) 
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.os.Looper.loop(Looper.java:123)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 17:44:34.220: E/AndroidRuntime(269):  at java.lang.reflect.Method.invokeNative(Native Method)
01-31 17:44:34.220: E/AndroidRuntime(269):  at java.lang.reflect.Method.invoke(Method.java:521)
01-31 17:44:34.220: E/AndroidRuntime(269):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-31 17:44:34.220: E/AndroidRuntime(269):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-31 17:44:34.220: E/AndroidRuntime(269):  at dalvik.system.NativeStart.main(Native Method)
01-31 17:44:34.220: E/AndroidRuntime(269): Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentsTable ORDER BY app_name ASC) 
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:34)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:64)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:283)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:264)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.support.v4.widget.CursorAdapter.getCount(CursorAdapter.java:202)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.widget.ListView.setAdapter(ListView.java:436)
01-31 17:44:34.220: E/AndroidRuntime(269):  at com.example.flybase2.ViewAppointments.onCreate(ViewAppointments.java:54)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-31 17:44:34.220: E/AndroidRuntime(269):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-31 17:44:34.220: E/AndroidRuntime(269):  ... 11 more
</code></pre>

<p>Currently at the moment I do not close the database using .searchApps.close();. If do this then I get the following logcat error:</p>

<pre><code>01-31 17:52:17.324: E/AndroidRuntime(277): FATAL EXCEPTION: main
01-31 17:52:17.324: E/AndroidRuntime(277): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.ViewAppointments}: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentsTable ORDER BY app_name ASC) 
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.os.Looper.loop(Looper.java:123)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 17:52:17.324: E/AndroidRuntime(277):  at java.lang.reflect.Method.invokeNative(Native Method)
01-31 17:52:17.324: E/AndroidRuntime(277):  at java.lang.reflect.Method.invoke(Method.java:521)
01-31 17:52:17.324: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-31 17:52:17.324: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-31 17:52:17.324: E/AndroidRuntime(277):  at dalvik.system.NativeStart.main(Native Method)
01-31 17:52:17.324: E/AndroidRuntime(277): Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentsTable ORDER BY app_name ASC) 
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:34)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:64)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:283)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:264)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.support.v4.widget.CursorAdapter.getCount(CursorAdapter.java:202)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.widget.ListView.setAdapter(ListView.java:436)
01-31 17:52:17.324: E/AndroidRuntime(277):  at com.example.flybase2.ViewAppointments.onCreate(ViewAppointments.java:56)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-31 17:52:17.324: E/AndroidRuntime(277):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-31 17:52:17.324: E/AndroidRuntime(277):  ... 11 more
</code></pre>
