I've checked at all the solutions, but I keep getting the error.
The database exists, and I could use the same database before with the same code, but now I'm getting this error. I need help from those who have received the same error before.
Thank you..
error image = https://ibb.co/GxBFznf
my DbHelper class;
public DbHelper(@Nullable Context context) {
super(context, DB_NAME, null, 1);
assert context != null;
DB_PATH = context.getApplicationInfo().dataDir + "/databases/";
openDataBase();
this.mContext = context;
}
public void openDataBase() {
String myPath = DB_PATH + DB_NAME;
mDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
}
public void copyDataBase() throws IOException {
try {
InputStream myInput = mContext.getAssets().open(DB_NAME);
String outputFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outputFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0)
myOutput.write(buffer, 0, length);
myOutput.flush();
myOutput.close();
myInput.close();
;
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean checkDataBase() {
SQLiteDatabase tempDB = null;
try {
String myPath = DB_PATH + DB_NAME;
File file = new File(myPath);
if(file.exists() && !file.isDirectory())
tempDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
} catch (SQLException e) {
e.printStackTrace();
}
if (tempDB != null)
tempDB.close();
return tempDB != null ? true : false;
}
public void createDataBase() throws IOException {
boolean isDBExist = checkDataBase();
if (isDBExist) {
} else {
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
e.printStackTrace();
}
}
}
my MainActivity;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = (SeekBar)findViewById(R.id.seekBar);
txtMode= (TextView) findViewById(R.id.txtMode);
btnPlay = (Button)findViewById(R.id.btnPlay);
btnScore = (Button)findViewById(R.id.btnScore);
db = new DbHelper(this);
try{
db.createDataBase();
}
catch (IOException e){
e.printStackTrace();
}