title: How can i fix SQLiteOpenHelper.getDatabaseLocked error while trying to access a SQLite database in android?
body: <p>I am trying to retrieve some data from a Sqlite database. But when I try to retrieve data using the method getTaskSent, I get the following errors. Can anyone suggest me a solution for the following errors?</p>
  
  <pre><code>  E/AndroidRuntime(23159):  at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
  </code></pre>
  
  <p>Here is my database code:</p>
  
  <pre><code>public class Databasehandler extends SQLiteOpenHelper{
  private static final String LOGCAT = null;
  
  public Databasehandler(Context applicationcontext) {
      super(applicationcontext,"androidsqlite.db", null, 4);
      // TODO Auto-generated constructor stub
      Log.d(LOGCAT,"Database Created");
  
  }
  @Override
  public void onCreate(SQLiteDatabase db) {
      // TODO Auto-generated method stub
      String query,query1,query2; 
      query = "CREATE TABLE userlogin ( phoneId INTEGER PRIMARY KEY,username TEXT,userid INTEGER,contacts TEXT UNIQUE)";
   query1 = "CREATE TABLE task ( TaskId INTEGER PRIMARY KEY,heading TEXT,desc TEXT,d1 TEXT,d2 TEXT,t1 TEXT,t2 TEXT,receiver TEXT,sender TEXT)";
   query2 = "CREATE TABLE me ( fbId INTEGER PRIMARY KEY,fbname TEXT,fbuserid INTEGER,fbpic BLOB,ph TEXT,email TEXT)"; 
   db.execSQL(query1);
      db.execSQL(query);
      db.execSQL(query2);
  
  }
   public void inserttask(HashMap&lt;String, String&gt; queryValues) {
      SQLiteDatabase database = this.getWritableDatabase();
      ContentValues values2 = new ContentValues();
      values2.put("heading", queryValues.get("heading"));
      values2.put("desc", queryValues.get("desc"));
      values2.put("d1", queryValues.get("d1"));
      values2.put("d2", queryValues.get("d2"));
      values2.put("t1", queryValues.get("t1"));
      values2.put("t2", queryValues.get("t2"));
      values2.put("sender", queryValues.get("sender"));
      values2.put("receiver", queryValues.get("receiver"));
  
      database.insert("task", null, values2);
      database.close();
  }
    public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getTaskSent() {
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; wordList;
      wordList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
      String selectQuery = "SELECT * FROM task";
  
      SQLiteDatabase database = this.getReadableDatabase();
      Cursor cursor = database.rawQuery(selectQuery, null);
      if (cursor.moveToFirst()) {
          do {
              HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
              //map.put("userid", cursor.getString(1));
              map.put("heading", cursor.getString(1));
              map.put("desc", cursor.getString(2));
              map.put("d1", cursor.getString(3));
              map.put("d2", cursor.getString(4));
              map.put("t1", cursor.getString(5));
              map.put("t2", cursor.getString(6)); 
              map.put("receiver", cursor.getString(7));                                                                                                           
  
              wordList.add(map);
          } while (cursor.moveToNext());
      }cursor.close();
      database.close();
  
  
      return wordList;
  }
  </code></pre>