我已经在stackoverflow上检查了所有与此相关的问题,但似乎没有一个对我有帮助。我的程序过去运行得非常好,然后我删除了我的 AVD,当我再次运行它时,它在尝试创建我的数据库文件夹时给了我这个错误。
我在清单文件中有读写权限,还有什么我可以提供给你的吗?
任何帮助将不胜感激,我不认为这是我的代码,因为我所做的只是重新创建我的 AVD,但过去两周我可能很幸运
public DataBaseHelper(Context context)
{
super(context, DB_NAME, null, 1);
if(android.os.Build.VERSION.SDK_INT >= 4.2)
{
DB_PATH = context.getApplicationInfo().dataDir + "/databases/";
}
else
{
DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
}
this.mContext = context;
}
public void createDataBase() throws IOException
{
//If database not exists copy it from the assets
copyDataBase();
mDataBase = this.getReadableDatabase();
boolean mDataBaseExist = checkDataBase();
if(!mDataBaseExist)
{
mDataBase = this.getReadableDatabase();
this.close();
try
{
//Copy the database from assests
copyDataBase();
Log.e(TAG, "createDatabase database created");
}
catch (IOException mIOException)
{
throw new Error("ErrorCopyingDataBase");
}
}
}
//Check that the database exists here: /data/data/your package/databases/Da Name
private boolean checkDataBase()
{
File dbFile = new File(DB_PATH + DB_NAME);
//Log.v("dbFile", dbFile + " "+ dbFile.exists());
this.getReadableDatabase();
return dbFile.exists();
}
//Copy the database from assets
private void copyDataBase() throws IOException
{
InputStream mInput = mContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream mOutput = new FileOutputStream(outFileName);
byte[] mBuffer = new byte[1024];
int mLength;
while ((mLength = mInput.read(mBuffer))>0)
{
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();
}
//Open the database, so we can query it
public boolean openDataBase() throws SQLException
{
String mPath = DB_PATH + DB_NAME;
//Log.v("mPath", mPath);
mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.OPEN_READWRITE);
//mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
return mDataBase != null;
}