title: Cannot write to sqlite from another activity
body: <p>I try to call a method and write to my database from another activity in android but my app crashes because it cannot write. My activity does not have On Create because it does not need it. Therefore I have this code:
  <code>DB db = new DB(ServSearcher.this);</code> which I want to give me acess to my Database and then I use my method below like:</p>
  
  <pre><code>List&lt;Contact&gt; contacts = db.getAllContacts();
  for (Contact cn : contacts) {
      db.addContact(new Contact(var, getTime()));
  </code></pre>
  
  <p>Here is my logcat error:</p>
  
  <pre><code>java.lang.NullPointerException
          at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:268)
          at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
          at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
          at com.android.SecondActivity.DB.getAllContacts(DB.java:88)
          at com.android.SecondActivity.ServSearcher$5.onAvailable(ServSearcher.java:189)
  </code></pre>
  
  <p>I think it is obvious that my app cannot write to database so this line is wrong <code>DB db = new DB(ServSearcher.this);</code> or at least does not gives me access, any ideas?</p>
  
  <p><strong>edit after V_J comment:</strong></p>
  
  <p>Here is my method on DB </p>
  
  <pre><code>public List&lt;Contact&gt; getAllContacts() {
  
          List&lt;Contact&gt; contactList = new ArrayList&lt;Contact&gt;();
      // Select All Query
      String selectQuery = "SELECT  * FROM " + TABLE_CONTACTS;
  
      SQLiteDatabase db = this.getWritableDatabase();
      Cursor cursor = db.rawQuery(selectQuery, null);
  
      // looping through all rows and adding to list
      if (cursor.moveToFirst()) {
          do {
              Contact contact = new Contact();
              contact.setTime(cursor.getInt(0));
              contact.setName(cursor.getString(1));
              // Adding contact to list
              contactList.add(contact);
          } while (cursor.moveToNext());
      }
  
      // return contact list
      return contactList;
  }
  </code></pre>