I've created G class in-order to using database but in first steps I got this error :
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
Also in AndroidManifest.xml I added :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
This is my G class :
package com.example.n5110.database;
import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import java.io.File;
public class G extends Application {
public static Context context;
public static SQLiteDatabase database;
public static final String DIR_SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
public static final String DIR_DATABASE = DIR_SDCARD + "/database-test/";
@Override
public void onCreate() {
super.onCreate();
context = this.getApplicationContext();
new File(DIR_DATABASE).mkdirs();
database = SQLiteDatabase.openOrCreateDatabase(DIR_DATABASE + "/database.sqlite", null);
}
}
Does anyone have an idea??
File dbFile = myContext.getDatabasePath(DB_NAME); return dbFile.exists();
Hope it helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.