我已经使用数据库创建了G类,但在第一步中我遇到了这个错误:
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
同样在AndroidManifest.xml中我添加了:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
这是我的G班:
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);
}
}
有没有人有想法?
答案 0 :(得分:0)
文件dbFile = myContext.getDatabasePath(DB_NAME); return dbFile.exists();
希望有所帮助