My error log :
2019-11-28 11:46:59.415 13936-13936/com.example.thongapps E/SQLiteLog: (14) cannot open file at line 35803 of [605907e73a]
2019-11-28 11:46:59.415 13936-13936/com.example.thongapps E/SQLiteLog: (14) os_unix.c:35803: (24) open(/data/user/0/com.example.thongapps/databases/dbThong) -
2019-11-28 11:46:59.421 13936-13936/com.example.thongapps E/SQLiteDatabase: Failed to open database '/data/user/0/com.example.thongapps/databases/dbThong'.
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:210)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:194)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:493)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:200)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:192)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:864)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:849)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:724)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:714)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:295)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:238)
at com.example.thongapps.DatabaseHelper.<init>(DatabaseHelper.java:86)
at com.example.thongapps.CustomeAdapter.removeDBItem(CustomeAdapter.java:448)
at com.example.thongapps.CustomeAdapter.access$100(CustomeAdapter.java:23)
at com.example.thongapps.CustomeAdapter$1.afterTextChanged(CustomeAdapter.java:114)
at android.widget.TextView.sendAfterTextChanged(TextView.java:9429)
at android.widget.TextView.setText(TextView.java:5434)
at android.widget.TextView.setText(TextView.java:5281)
at android.widget.EditText.setText(EditText.java:117)
at android.widget.TextView.setText(TextView.java:5238)
at com.example.thongapps.CustomeAdapter.getView(CustomeAdapter.java:84)
The Strange thing is, when i do it in slow way, all is fine, but when i do it in faster way to editText, database leak and cant open. My Trigger function is to delete when the user set 0/remove anything in editText(editText inside listview, multiple editText in row and more than 1 row) then the record is removed in database. When i add no any problem(using button), but for delete
cz some reason i need to update manually each update in row. And there is case, when record not yet to save and user change to 0/remove data inside editText but this already in my exception.
So my question is why when i doing CRUD data in other function is fine, but in function remove editText got stuck. Only when i remove/set to 0(trigger to remove record) with fast, but when i doing it in slow way everything is alright.
just make little clear my problem almost same like : Getting error while executing getwritabledatabase() in android
So how i can init the db ? is something wrong with my db,
private Context mContext;
SQLiteDatabase db;
public DatabaseHelper(Context context ){
super(context, DATABASE_NAME, null,DATABASE_VERSION );
mContext = context;
db = this.getWritableDatabase();
}
public static DatabaseHelper getInstance(Context ctx) {
if (dInstance == null) {
dInstance = new DatabaseHelper(ctx.getApplicationContext());
}
return dInstance;
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
Log.w(DatabaseHelper.class.getName(),
"Upgrading database from version " + i + " to "
+ i1 + ", which will destroy all old data");
db.execSQL(tableDBVersion.UPGRADE_TABLE_DBVERSION);
onCreate(db);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(tableDBVersion.CREATE_TABLE_DBVERSION);
db.execSQL(tableDBVersion.SEED_TABLE_DBVERSION);
}
Using Getting "Failed to open database" error when copying a sqlite database from assets In Android 4.2, still got same error. Idk if it correct way to implement to my code :
public DatabaseHelper(Context context ){
super(context, DATABASE_NAME, null,DATABASE_VERSION );
mContext = context;
if(!checkDataBase()){
db = this.getWritableDatabase();
}
}
private boolean checkDataBase() {
File databasePath = mContext.getDatabasePath(DATABASE_NAME);
return databasePath.exists();
}