title: close() was not explicity called on database
body: <p>I need to know where to call the db.close() in my code. I've added it on onCreate() method, but when I need to use some methods it says database not open, and then I've removed from onCreate() and it says close() was not explicity called. so where should I close, could it be inside each method of the class??</p>
  
  <p>here is the code:</p>
  
  <pre><code>public class HoursPerDayDataHelper {
  
  private static final String DATABASE_NAME = "database.db";
  private static final int DATABASE_VERSION = 1;
  protected static final String TABLE_NAME = "table";
  protected String TAG = "HoursPerDayDataHelper";
  
  private Context context;
  private SQLiteDatabase db;
  OpenHelper openHelper = null;
  
  public HoursPerDayDataHelper(Context context) {
      this.context = context;
      openHelper = new OpenHelper(this.context);
      this.db = openHelper.getWritableDatabase();
      openHelper.onCreate(db);
  
  }
  
  public void close() {
  
      if (openHelper != null) {
          openHelper.close();
      }
  
  }
  
  public void deleteAll() {
      this.db.delete(TABLE_NAME, null, null);
  }
  
  public String selectDuration(String date) {
  
      String duration = "";
      Integer value = 0;
      String returnment = "";
      Log.i(TAG, "date do select: " + date);              
  
      Cursor cursor = this.db.query(TABLE_NAME, new String[] { "duration" },
              "date = ? ", new String[]{ date }, null, null, null);
  
      Log.i(TAG, "cursor string " + cursor);
  
      if (cursor.moveToFirst()) {
          do {
              Log.i(TAG, "dentro do if cursor");
              duration = cursor.getString(0);
              value += Integer.parseInt(duration);
  
          } while (cursor.moveToNext());
          returnment = Integer.toString(value);
      }else{
  
          Log.i(TAG, "bla bla bla");
  
      }
  
      if (cursor != null &amp;&amp; !cursor.isClosed()) {
          cursor.close();
  
      }
      return returnment;
  }
  
  public ArrayList&lt;String[]&gt; selectTopContacts() {
  
      ArrayList&lt;String[]&gt; list1 = new ArrayList&lt;String[]&gt;();
      Cursor cursor = this.db.query(TABLE_NAME, null, null, null, null, null,
              "duration desc");
  
      if (cursor.moveToFirst()) {
          do {
              if (cursor.getString(2) != "") {
  
                  String[] data = new String[4];
                  data[0] = cursor.getString(2);
                  data[1] = cursor.getString(4);
                  data[2] = cursor.getString(5);
                  data[3] = cursor.getString(7);
  
                  list1.add(data);
  
              } else {
  
                  String[] data = new String[3];
                  data[1] = cursor.getString(4);
                  data[2] = cursor.getString(5);
                  data[3] = cursor.getString(7);
  
                  list1.add(data);
  
              }
          } while (cursor.moveToNext());
      }
      if (cursor != null &amp;&amp; !cursor.isClosed()) {
          cursor.close();
  
      }
      return list1;
  }
  
  public static class OpenHelper extends SQLiteOpenHelper {
  
      OpenHelper(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          db.execSQL("CREATE TABLE IF NOT EXISTS "
                  + TABLE_NAME
                  + "(id INTEGER PRIMARY KEY AUTOINCREMENT, duration TIME, date DATE, current_time TIME)");
  
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          Log.w("HoursPerDay Database",
                  "Upgrading database, this will drop tables and recreate.");
          db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
          onCreate(db);
      }
  }
  
  }
  </code></pre>
  
  <p><strong>And this is my Activity:</strong></p>
  
  <pre><code>public class HoursPerDay extends Activity{
  
  private String LOG_TAG = "HoursPerDay";
  private TextView mDateDisplay;
  public String date;
  private int mYear;
  private int mMonth;
  private int mDay;
  private int newDay;
  private String hpdData; 
  private HoursPerDayDataHelper hpd;
  
  OpenHelper openHelper = new OpenHelper(HoursPerDay.this);
  
  static final int DATE_DIALOG_ID = 0;
  
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.hours_per_day);
  
      hpd = new HoursPerDayDataHelper(this);
  
      // capture our View elements
      mDateDisplay = (TextView) findViewById(R.id.dateDisplay);   
  
      // get the current date
      final Calendar c = Calendar.getInstance();
      mYear = c.get(Calendar.YEAR);
      mMonth = c.get(Calendar.MONTH);
      mDay = c.get(Calendar.DAY_OF_MONTH);
      // display the current date (this method is below)
  }
  
  @Override
  protected void onDestroy() {
      super.onDestroy();
      if (openHelper != null) {
          openHelper.close();
      }
      if (hpd != null) {
          hpd.close();
      }
  }
  
  // the callback received when the user "sets" the date in the dialog
  private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
  
      public void onDateSet(DatePicker view, int year, int monthOfYear,
              int dayOfMonth) {
  
          mYear = year;
          mMonth = monthOfYear;
          mDay = dayOfMonth;                  
  
          setBasicContent();
  
          hpd.close();
  
  
      }
  };
  
  protected Dialog onCreateDialog(int id) {
      switch (id) {
      case DATE_DIALOG_ID:
          return new DatePickerDialog(this,
                      mDateSetListener,
                      mYear, mMonth, mDay);
      }
      return null;
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu){
  
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.layout.hoursperdaymenu, menu);
      return true;
  
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item){
  
      switch(item.getItemId()){
  
      case R.id.filter_by_day:            
              showDialog(DATE_DIALOG_ID);
              return true;
      case R.id.filter_by_user:
  
          showDialog(DATE_DIALOG_ID);
          return true;
  
      default:
          return super.onOptionsItemSelected(item);
      }
  
  }   
  
  public void setBasicContent() {
  
      date = (mMonth + 1) + "/" + newDay + "/" + mYear;       
      hpdData = this.hpd.selectDuration(date);
      mDateDisplay.setText(hpdData);
      hpd.close();
  }
  
  }
  </code></pre>