title: Android ListView: Application did not close the cursor or database object
body: <p>My <code>listview</code> activity will not display a particular row(<code>sName</code>) in my List view <code>UI</code>. I am able to add item to me <code>sqlite</code> DB but after trying to get my <code>listview</code> to refresh when my DB is updated, my list view is blank. </p>
  
  <p>I do not receive any error when data is <code>added\updated\removed</code>. I do receive logcat error saying the cursor or DB was not closed when the app is launched. " <code>android.database.sqlite.DatabaseObjectNotClosedException:</code> Application did not close the cursor or database object that was opened here" please advise. logcat and code are below.</p>
  
  <p>activity:</p>
  
  <pre><code>   public class LoginList extends Activity implements OnClickListener,    OnItemClickListener {
  
    private ListView loginList;
    private Button webLogin;
  
    private ListAdapter loginListAdapter;
  
    private ArrayList&lt;LoginDetails&gt; loginArrayList;
  
    List&lt;String&gt; arrayList = new ArrayList&lt;String&gt;();
  
  
  
   @Override 
   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
  
   loginListAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, populateList());
   setContentView(R.layout.login_listview);
  
   arrayList = populateList();
  
  
   loginList = (ListView)
   findViewById(R.id.loginlist);
   loginList.setOnItemClickListener(this);
  
   webLogin = (Button)
   findViewById(R.id.button3);
   webLogin.setOnClickListener(this);
  
  
   }
  
  @Override
  public void onClick (View v) {
  Intent webLoginIntent = new Intent (this, LoginPlusActivity.class);
  startActivity(webLoginIntent);
  
  }
  
  public List&lt;String&gt; populateList(){
  
  ArrayList&lt;LoginDetails&gt; loginArrayList = new ArrayList&lt;LoginDetails&gt;();
  List&lt;String&gt; webNameList = new ArrayList&lt;String&gt;();
  
  dataStore openHelperClass = new dataStore (this);
  
  SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();
  
  Cursor cursor = sqliteDatabase.query(dataStore.TABLE_NAME_INFOTABLE, null, null, null,  null, null, dataStore.COLUMN_NAME_SITE, null);
  
  startManagingCursor(cursor);
  
  
  while (cursor.moveToNext()){
  String sName = cursor.getString(cursor.getColumnIndex(dataStore.COLUMN_NAME_SITE));
  String wUrl = cursor.getString(cursor.getColumnIndex(dataStore.COLUMN_NAME_ADDRESS));
  String uName = cursor.getString(cursor.getColumnIndex(dataStore.COLUMN_NAME_USERNAME));
  String pWord = cursor.getString(cursor.getColumnIndex(dataStore.COLUMN_NAME_PASSWORD));
  String lNotes = cursor.getString(cursor.getColumnIndex(dataStore.COLUMN_NAME_NOTES));
  
  LoginDetails lpDetails = new LoginDetails();
  
    lpDetails.setsName(sName);
    lpDetails.setwUrl(wUrl);
    lpDetails.setuName(uName);
    lpDetails.setpWord(pWord);
    lpDetails.setlNotes(lNotes);
  
    loginArrayList.add(lpDetails);
    webNameList.add(sName);
   }
  
   cursor.close();
   sqliteDatabase.close();
   return webNameList;
   }
  
  
  
  @Override
  protected void onResume() {
  super.onResume();
  
  
  
  
  arrayList.clear();
  
  arrayList = populateList();
  
  SimpleCursorAdapter loginListAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, null, null);
  loginListAdapter.notifyDataSetChanged();
  
  }
  
  @Override
   public void onItemClick(AdapterView&lt;?&gt; arg0 , View arg1, int arg2, long arg3) {
   Toast.makeText(getApplicationContext(), "Selected ID :" + arg2,     Toast.LENGTH_SHORT).show();
  
   Intent updateDeleteLoginInfo = new Intent (this, UpdateDeleteLoginList.class);
  
  
  
   LoginDetails clickedObject = loginArrayList.get(arg2);
  
    Bundle loginBundle = new Bundle();
    loginBundle.putString("clickedWebSite",clickedObject.getsName());
    loginBundle.putString("clickedWebAddress",clickedObject.getwUrl());
    loginBundle.putString("clickedUserName",clickedObject.getuName());
    loginBundle.putString("clickedPassWord",clickedObject.getpWord());
    loginBundle.putString("clickedNotes",clickedObject.getlNotes());
  
    updateDeleteLoginInfo.putExtras(loginBundle);
  
    startActivityForResult(updateDeleteLoginInfo, 0);   
     }
    }
  </code></pre>
  
  <p>Revised Activity :</p>
  
  <pre><code>     public class LoginList extends FragmentActivity implements OnClickListener, OnItemClickListener, LoaderManager.LoaderCallbacks&lt;Cursor&gt; {
  
   private ListView loginList;
   private Button webLogin;
   private CursorAdapter adapter;
   private static final int LOADER_ID = 0x02;
  
   private ArrayList&lt;LoginDetails&gt; loginArrayList;
  
  @Override 
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  setContentView(R.layout.login_listview);
  getSupportLoaderManager().initLoader(LOADER_ID, null, this);
  
  loginList = (ListView)
   findViewById(R.id.loginlist);
  loginList.setOnItemClickListener(this);
  
  webLogin = (Button)
   findViewById(R.id.button3);
  webLogin.setOnClickListener(this);
  
  loginArrayList = new ArrayList&lt;LoginDetails&gt;();
  adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null,
  new String[] { dataStore.COLUMN_NAME_SITE}, new int[]{R.id.textView1});
  loginList.setAdapter(adapter);
   }
  
    public Loader&lt;Cursor&gt; onCreateLoader(int i, Bundle bundle) {
  return new CursorLoader(this, Uri.parse(null), null, null, null, null);
     }
    public void onLoadFinished(Loader&lt;Cursor&gt; cursorLoader, Cursor cursor) {
  adapter.swapCursor(cursor);
  }
    public void onLoaderReset(Loader&lt;Cursor&gt; cursorLoader) {
  adapter.swapCursor(null);
  }
  </code></pre>