Skip to content Skip to sidebar Skip to footer

Android - Could Not Open Database

I have my db.sqlite file in the Asset folder and I get this error when I try to open it: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could

Solution 1:

you need to check the existence of the database file first which you are not doing here

DataBaseHelperdbHelper=newDataBaseHelper(this);
dbHelper.openDataBase();

you are simply making an object of DataBaseHelper and then calling .openDataBase()

try this constructor :

publicDataBaseHelper(Context context) {
    super(context, DB_NAME, null, 1);
   this.myContext = context;
   try{
        StringmyPath= DB_PATH + DB_NAME; // also check the extension of you db file Filedbfile=newFile(myPath);                
            if( dbfile.exists());
             Toast.makeText(context, "database exists", Toast.LENGTH_LONG).show();
            else
             Toast.makeText(context, "cant find database", Toast.LENGTH_LONG).show();
        }
        catch(SQLiteException e){
            System.out.println("Database doesn't exist");
        }

}

Post a Comment for "Android - Could Not Open Database"