title: no such table: quotes (code 1 SQLITE_ERROR) : Android P
body: <p>I have one quotes application in which I am using SqlLite Database for store quotes. When User Open Application, its copy data from Assets to database. Its working fine in all version but in Android P its crashing on application start.</p>
  
  <p>its giving me error like </p>
  
  <pre><code>android.database.sqlite.SQLiteException: no such table: quotes (code 1 SQLITE_ERROR): , while compiling: SELECT COUNT(qu_text) AS count FROM quotes
  </code></pre>
  
  <p>I am sure that database does not getting copied, so there no table error coming but its only for Android P. Other version is working fine.</p>
  
  <p>My DBHandler.java is like below</p>
  
  <pre><code>public class DBHandler extends SQLiteOpenHelper {
      private static String DB_PATH;
      private static String DB_NAME = "xxx";
      private SQLiteDatabase myDataBase;
      private final Context myContext;
  
      DBHandler(Context context) {
  
          super(context, DB_NAME, null, constant.DATABASE_VERSION);
          this.myContext = context;
          DB_PATH = context.getDatabasePath(DB_NAME).toString();
      }
      void createDataBase() throws IOException {
  
          boolean dbExist = checkDataBase();
  
          if (dbExist) {
              Log.e("database","exist");
          } else {
  
              this.getReadableDatabase();
  
              try {
                  copyDataBase();
  
              } catch (IOException e) {
  
                  throw new Error("Error copying database");
  
              }
          }
  
      }
  
      private boolean checkDataBase() {
  
          SQLiteDatabase checkDB = null;
  
          try {
              String myPath = DB_PATH;
              checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
  
          } catch (SQLiteException e) {
  
              // database does't exist yet.
  
          }
  
          if (checkDB != null) {
  
              checkDB.close();
  
          }
  
          return checkDB != null;
      }
  
  
      private void copyDataBase() throws IOException {
  
          InputStream myInput = myContext.getAssets().open(DB_NAME);
  
          String outFileName = DB_PATH;
  
          OutputStream myOutput = new FileOutputStream(outFileName);
  
          byte[] buffer = new byte[1024];
          int length;
          while ((length = myInput.read(buffer)) &gt; 0) {
              myOutput.write(buffer, 0, length);
          }
  
          myOutput.flush();
          myOutput.close();
          myInput.close();
  
      }
  
      // ==============================================================================
  
      void openDataBase() throws SQLException {
  
          String myPath = DB_PATH;
          myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
  
      }
  
  
      // ==============================================================================
  
      @Override
      public synchronized void close() {
  
          if (myDataBase != null)
              myDataBase.close();
  
          super.close();
  
      }
  
      // ==============================================================================
  
      @Override
      public void onCreate(SQLiteDatabase db) {
  
      }
  
      // ==============================================================================
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
      }
  
  }
  </code></pre>
  
  <p>and class DAO.java has functions like below</p>
  
  <pre><code>private void open() throws SQLException {
      if(database!=null&amp;&amp;database.isOpen())return;
      database = dbHandler.getWritableDatabase();
  
  }
  
  
  private void closeDAO(){
      synchronized (lockObj){
          if(dbHandler!=null)dbHandler.close();
          dbHandler=null;
          database=null;
      }
  }
  
  
  
  public static void dispose(){
  
      if(dBObject!=null){
          dBObject.closeDAO();
      }
      dBObject=null;
  }
  </code></pre>
  
  <p>I have tried to close database connection like below before copy database as one of user have told in answer but still same errors coming .</p>
  
  <pre><code>private void copyDataBase() throws IOException {
          SQLiteDatabase db = getReadableDatabase();
          db.close();
  
          InputStream myInput = myContext.getAssets().open(DB_NAME);
  
          String outFileName = DB_PATH;
  
          OutputStream myOutput = new FileOutputStream(outFileName);
  
          byte[] buffer = new byte[1024];
          int length;
          while ((length = myInput.read(buffer)) &gt; 0) {
              myOutput.write(buffer, 0, length);
          }
  
          myOutput.flush();
          myOutput.close();
          myInput.close();
  
      }
  </code></pre>
  
  <p>Let me know if someone can help to solve the puzzle. Thanks</p>