title: Attempt to invoke virtual method error when i try to access data android
body: <p>I'm a newbie in android world, when I try to get data from the database, I meet this error, bellow is my database access code </p>
  
  <pre><code>public static boolean Checkduplicate(String activity_name, String location, String date) {
      SQLiteDatabase dtb = ActivityHandler.db;
      String Query = "Select * from  Activity  where activity_name = " + activity_name + "and location =" + location + "and _date =" + date;
      Cursor cursor = dtb.rawQuery(Query, null);
      if(cursor.getCount() &lt;= 0){
          cursor.close();
          return true;
      }
      cursor.close();
      return false;
  }
  </code></pre>
  
  <p>Here is the error</p>
  
  <pre><code>FATAL EXCEPTION: main
                Process: com.example.vinhg.comp1661_nguyengiavinh, PID: 31092
                java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.rawQuery(java.lang.String, java.lang.String[])' on a null object reference
                    at com.example.vinhg.comp1661_nguyengiavinh.ActivityHandler.Checkduplicate(ActivityHandler.java:32)
                    at com.example.vinhg.comp1661_nguyengiavinh.MainActivity.addData(MainActivity.java:41)
                    at com.example.vinhg.comp1661_nguyengiavinh.MainActivity$1.onClick(MainActivity.java:32)
                    at android.view.View.performClick(View.java:5340)
                    at android.view.View$PerformClick.run(View.java:21610)
                    at android.os.Handler.handleCallback(Handler.java:815)
                    at android.os.Handler.dispatchMessage(Handler.java:104)
                    at android.os.Looper.loop(Looper.java:207)
                    at android.app.ActivityThread.main(ActivityThread.java:5763)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
  </code></pre>
  
  <p>Here is my full ActivityHandler class</p>
  
  <pre><code>public class ActivityHandler {
  private static SQLiteDatabase db;
  public  ActivityHandler(Context context){
      DatabaseHandler dbDatabaseHandler = new DatabaseHandler(context);
      this.db = dbDatabaseHandler.getWritableDatabase();
  }
  
  @Override
  protected void finalize() throws Throwable {
      try{
          db.close();
      }catch (Exception ex){
  
      }
      super.finalize();
  }
  
  public static boolean Checkduplicate(String activity_name, String location, String date) {
      SQLiteDatabase dtb = ActivityHandler.db;
      String Query = "Select * from  Activity  where activity_name = " + activity_name + "and location =" + location + "and _date =" + date;
      Cursor cursor = dtb.rawQuery(Query, null);
      if(cursor.getCount() &lt;= 0){
          cursor.close();
          return true;
      }
      cursor.close();
      return false;
  }
  </code></pre>