Android sqlite返回:错误代码=14,msg=无法在源代码行25467处打开文件

Android sqlite返回:错误代码=14,msg=无法在源代码行25467处打开文件,android,android-sqlite,Android,Android Sqlite,我是第一次在android中处理SQLite开发。 目前,我有现有的sqlite数据库,我想复制资产文件夹中的粘贴,然后读取它。 但我面临以下问题: 我的地址: 09-21 13:08:23.725: I/Database(11660): sqlite returned: error code = 14, msg = cannot open file at source line 25467 09-21 13:08:23.784: E/Database(11660): sqlite3_open_

我是第一次在android中处理SQLite开发。 目前,我有现有的sqlite数据库,我想复制资产文件夹中的粘贴,然后读取它。 但我面临以下问题:

我的地址:

09-21 13:08:23.725: I/Database(11660): sqlite returned: error code = 14, msg = cannot open file at source line 25467
09-21 13:08:23.784: E/Database(11660): sqlite3_open_v2("/data/data/YOUR_PACKAGE/databases/myDBName", &handle, 1, NULL) failed
09-21 13:08:23.866: I/In createDataBase();IOException(11660): myDBName
我在谷歌上搜索了很多,找到了解决方案,并据此更新了我的代码,但仍然面临着这个问题。我不知道问题出在哪里

我的代码如下:

public class DataBaseHelper extends SQLiteOpenHelper{

private static String DB_PATH = "/data/data/com.example.androidtestapplication/databases/";

private static String DB_NAME = "myDBName";

private SQLiteDatabase myDataBase; 

private final Context myContext;

public DataBaseHelper(Context context) {

    super(context, DB_NAME, null, 1);
    this.myContext = context;
}   
public void createDataBase() throws IOException{

    boolean dbExist = checkDataBase();

    if(dbExist){
        //do nothing - database already exist
    }
    else{
            this.getReadableDatabase();

        try {

            copyDataBase();

        } 
            catch (IOException e) {

            //throw new Error("Error copying database");
            Log.i("In createDataBase();IOException",e.getMessage());

        }
    }

}

private boolean checkDataBase(){

    SQLiteDatabase checkDB = null;

    try{
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

    }catch(SQLiteException e){

        //database does't exist yet.

    }

    if(checkDB != null){

        checkDB.close();

    }

    return checkDB != null ? true : false;
}


private void copyDataBase() throws IOException{

    //Open your local db as the input stream
    InputStream myInput = myContext.getAssets().open(DB_NAME);

    // Path to the just created empty db
    String outFileName = DB_PATH + DB_NAME;

    //Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);

    //transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer))>0){
        myOutput.write(buffer, 0, length);
    }

    //Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();

}

public void openDataBase() throws SQLException{

    //Open the database
    String myPath = DB_PATH + DB_NAME;
    myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

}

@Override
public synchronized void close() {

        if(myDataBase != null)
            myDataBase.close();

        super.close();

}

@Override
public void onCreate(SQLiteDatabase db) {

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}
MainActivity.java文件是:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    DataBaseHelper myDbHelper = new DataBaseHelper(this);
    myDbHelper = new DataBaseHelper(this);

    try {
        myDbHelper.createDataBase();
    } 
    catch (IOException ioe) {
        //throw new Error("Unable to create database");
        Log.i("In MainActivity:IOException",ioe.getMessage());
    }

    try {
        myDbHelper.openDataBase();

    }
    catch(SQLException sqle){

        //throw sqle;
        Log.i("In MainActivity:SQLException",sqle.getMessage());

    }
}
}
我还将以下权限添加到清单文件中:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

我已经完成了以下教程:

请让我知道我错过了什么

请帮助我…提前谢谢…:)

可能的副本