title: onCreate method in SQLiteOpenHelper class is not called even though the table doesn't exist
body: <p>Here is my code:</p>
  
  <pre><code>public class ResultDbHandler extends DatabaseHandler {
      private final String TABLE_RESULTS = "results";
  
      private final String RESULT_ORDER = "order";
      private final String RESULT_PROFILE = "resultProfileId";
      private final String RESULT_FVC = "fvc";
      private final String RESULT_FEV1 = "fev1";
      private final String RESULT_PEV = "pev";
      private final String RESULT_TIME = "time";
  
  
      public ResultDbHandler(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          final String query = "CREATE TABLE " + TABLE_RESULTS + " ("
                  + RESULT_ORDER + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                  + RESULT_PROFILE + " TEXT, "
                  + RESULT_FVC + " REAL, "
                  + RESULT_FEV1 + " REAL, "
                  + RESULT_PEV + " REAL, "
                  + RESULT_TIME + " TEXT, "
                  + "FOREIGN KEY(" + RESULT_PROFILE + ") REFERENCES "
                  + ProfileDbHandler.TABLE_PROFILES + "(" + ProfileDbHandler.PROFILE_ID + "))";
          db.execSQL(query);
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          db.execSQL("DROP TABLE IF EXISTS " + TABLE_RESULTS);
          onCreate(db);
      }
  
      @Override
      public boolean isDbExist() {
          return countRecord() &gt; 0;
      }
  
      @Override
      public int countRecord() {
          SQLiteDatabase db = getReadableDatabase();
          final String query = "SELECT count(*) FROM " + TABLE_RESULTS;
          Cursor cursor = db.rawQuery(query, null);
          int result = cursor.moveToFirst() ? cursor.getInt(0) : 0;
          cursor.close();
          db.close();
          return result;
      }
  </code></pre>
  
  <p>Anyway, <code>DatabaseHandler</code> directly extends <code>SQLiteOpenHelper</code>. Then, I simply call <code>isDbExist()</code> right after initializing <code>dbHandler</code> object which is like</p>
  
  <pre><code>...
  dbHandler = new ResultDbHandler(activity);
  dbHandler.isDbExist();
  ...
  </code></pre>
  
  <p>Somehow, the app crashed and the logcat said:</p>
  
  <pre><code>09-09 22:34:58.904 4789-4789/? E/SQLiteLog: (1) no such table: results
  09-09 22:34:58.907 4789-4789/? D/AndroidRuntime: Shutting down VM
  09-09 22:34:58.910 4789-4789/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.kahl.silir, PID: 4789
                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kahl.silir/com.kahl.silir.main.history.MeasurementResultActivity}: android.database.sqlite.SQLiteException: no such table: results (code 1): , while compiling: SELECT count(*) FROM results
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2464)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2526)
                                                       at android.app.ActivityThread.access$800(ActivityThread.java:169)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
                                                       at android.os.Handler.dispatchMessage(Handler.java:111)
                                                       at android.os.Looper.loop(Looper.java:194)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5549)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
                                                    Caused by: android.database.sqlite.SQLiteException: no such table: results (code 1): , while compiling: SELECT count(*) FROM results
                                                       at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                       at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:898)
                                                       at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:509)
                                                       at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                                                       at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
                                                       at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37)
                                                       at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
                                                       at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1346)
                                                       at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1285)
                                                       at com.kahl.silir.databasehandler.ResultDbHandler.countRecord(ResultDbHandler.java:64)
                                                       at com.kahl.silir.databasehandler.ResultDbHandler.isDbExist(ResultDbHandler.java:57)
                                                       at com.kahl.silir.main.history.MeasurementResultActivity.onCreate(MeasurementResultActivity.java:54)
                                                       at android.app.Activity.performCreate(Activity.java:5977)
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2526) 
                                                       at android.app.ActivityThread.access$800(ActivityThread.java:169) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                       at android.os.Looper.loop(Looper.java:194) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5549) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:372) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759) 
  </code></pre>
  
  <p>I have no idea why <code>onCreate</code> method from <code>ResultDbHandler</code> isn't called even though it said the table didn't exist. I've just done the same pattern in another activity using another direct child of <code>DatabaseHandler</code>. It works properly. Please kindly explain to me, why could this happen and how to fix it?</p>