title: Failed Android Login with SQLite Database
body: <p>I'm trying to create a login system for an android app using SQLite Database
  Then I use class DatabaseHelper.java:</p>
  <pre><code>private static final String DATABASE_NAME = &quot;test.db&quot;;
  private final Context context;
  SQLiteDatabase db;
  
  private static final String DATABASE_PATH = 
  &quot;/data/data/com.example.test2application/databases/&quot;;
  private final String USER_TABLE = &quot;user&quot;;
  
  public DatabaseHelper(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
      this.context = context;
      createDb();
  }
  @Override
  public void onCreate(SQLiteDatabase db) {
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  }
  
  public void createDb(){
      boolean dbExist = checkDbExist();
  
      if(!dbExist){
          this.getReadableDatabase();
          copyDatabase();
      }
  }
  private boolean checkDbExist(){
      SQLiteDatabase sqLiteDatabase = null;
  
      try{
          String path = DATABASE_PATH + DATABASE_NAME;
          sqLiteDatabase = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
      } catch (Exception ex){
      }
  
      if(sqLiteDatabase != null){
          sqLiteDatabase.close();
          return true;
      }
      return false;
  }
  private void copyDatabase(){
      try {
          InputStream inputStream = context.getAssets().open(DATABASE_NAME);
          String outFileName = DATABASE_PATH + DATABASE_NAME;
          OutputStream outputStream = new FileOutputStream(outFileName);
          byte[] b = new byte[1024];
          int length;
          while ((length = inputStream.read(b)) &gt; 0){
              outputStream.write(b, 0, length);
          }
          outputStream.flush();
          outputStream.close();
          inputStream.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
  }
  private SQLiteDatabase openDatabase(){
      String path = DATABASE_PATH + DATABASE_NAME;
      db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READWRITE);
      return db;
  }  
  public boolean checkUserExist(String username, String password){
      String[] columns = {&quot;username&quot;};
      db = openDatabase();
  
      String selection = &quot;username=? and password = ?&quot;;
      String[] selectionArgs = {username, password};
  
      Cursor cursor = db.query(USER_TABLE, columns, selection, selectionArgs, null, null, null);
      int count = cursor.getCount();
  
      cursor.close();
      close();
  }
  </code></pre>
  <p>but my app crushes with error :
  ####################################################################################################################################################
  E/SQLiteLog: (26) file is encrypted or is not a database
  E/DefaultDatabaseErrorHandler: Corruption reported by sqlite on database: /data/data/com.example.test2application/databases/test.db
  !@ dbObj has been closed
  E/SQLiteLog: (28) failed to open &quot;/data/data/com.example.test2application/databases/test.db&quot; with flag (131074) and mode_t (0) due to error (2)
  (28) failed to open &quot;/data/data/com.example.test2application/databases/test.db&quot; with flag (131072) and mode_t (0) due to error (2)
  (14) cannot open file at line 32546 of [9491ba7d73]
  (14) os_unix.c:32546: (2) open(/data/data/com.example.test2application/databases/test.db) -
  E/SQLiteDatabase: Failed to open database '/data/data/com.example.test2application/databases/test.db'.
  android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1294): Could not open database
  #################################################################
  Error Code : 1294 (SQLITE_CANTOPEN_ENOENT)
  Caused By : Specified directory or database file does not exist.
  (unknown error (code 1294): Could not open database)
  #################################################################</p>