title: Reading existing Sqlite database
body: <p>I have a ListView that fills from existing database, when user clicked on each item, one of the other columns, should be displayed on second Activity <code>(Like dictionary App</code>) </p>
  
  <p>But I can't execute any queries on second activity.</p>
  
  <p>I'm using <code>SqliteAssetHelper</code> library.</p>
  
  <p>Database class:</p>
  
  <pre><code>public class MyDatabase extends SQLiteAssetHelper {
  
  private static final String DATABASE_NAME    = "database.db";
  private static final int    DATABASE_VERSION = 1;
  
  
  public MyDatabase(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }
  
  }
  </code></pre>
  
  <p>On the first activity, listView filled from the database:</p>
  
  <pre><code> private void fillFromDb() {
      G.itemLists.clear();
      Cursor cursor = mydb.rawQuery("select * from test order by title limit 0,50 ", null);
      while (cursor.moveToNext()) {
          StructNote test1 = new StructNote();
          test1.title = cursor.getString(cursor.getColumnIndex("title"));
          G.itemLists.add(test1);
      }
      cursor.close();
      mydb.close();
      adapter.notifyDataSetChanged();
      }
  </code></pre>
  
  <p>but the problem is in the second activity; I can't execute any queries!</p>
  
  <pre><code>public class ActivityResult extends Activity {
  
  private MyDatabase    MyDataBase;
  public SQLiteDatabase mydb;
  
  
  @Override
  protected void onResume() {
      G.currentActivity = this;
      super.onResume();
  }
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.result);
  
      Cursor cursor = mydb.rawQuery("SELECT * FROM test ", null);
      while (cursor.moveToNext()) {
          try {
              Log.i("LOG", cursor.getString(cursor.getColumnIndex("title")));
          }
          catch (Exception e) {}
      }
      cursor.close();
      mydb.close();
  
  }
  
   }
  </code></pre>
  
  <p>logcat: <code>NullPointerException</code></p>
  
  <p>Many thanks...</p>
  
  <p>My question was not duplicate! Other answers that I found about NullPointerException were not fully addressing my question :) </p>
  
  <p>Because my problem and solution was only in use of <code>SqliteAssetHelper</code> library, that I couldn't find anything about it ;)</p>