我在使用 sqlite open helper 时遇到问题,我收到此错误:
sqlite3_open_v2("/data/data/lam.ztl.lamztlbologna/databases/ztlBolo.db", &handle, 2, NULL) failed 打开数据库失败。关闭它。android.database.sqlite.SQLiteCantOpenDatabaseException: 无法打开数据库文件我不明白为什么会收到这个错误。
我的开放助手类是:
enter code here
public class DBHelper extends SQLiteOpenHelper {
    private final static String DATABASE_NAME = "ztlBolo.db";
    static SQLiteDatabase db;
    //private  static String DB_PATH = "/data/data/lam.ztl.lamztlbologna/databases/";
    static Context context;
    private  static String DB_PATH = "/data/data/"+context.getPackageName()+"/databases/";
    private final static String TABLE_NAME = "manageZtlStreet";
    private final static String SQL_PATH = "databaseZtlBolo.sql";
    MapsActivity ma = new MapsActivity();
    Double LATITUDE= 0.0;
    Double LONGITUDE = 0.0;
    private final Context myContext;
    private final String CREATE_TABLE_ZTL_STREET = "CREATE TABLE manageZtlstreet ("
            + " via text not null,"
            +"latitude DOUBLE," 
            + "longitude DOUBLE);";
    public DBHelper(Context context,int version) {
        super(context, DBHelper.DATABASE_NAME,null,1);
        this.myContext = context;
    }
    @Override
    public void onCreate(SQLiteDatabase database) {
        //  database.openOrCreateDatabase(database.getPath(), null);
        database=SQLiteDatabase.openDatabase(database.getPath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.OPEN_READWRITE|SQLiteDatabase.CREATE_IF_NECESSARY);
        database.execSQL(this.CREATE_TABLE_ZTL_STREET);
        //DB_PATH = db.getPath();
        try {
            copyDataBase(database);
            Log.e("copy","copy");
        } catch (IOException e) {
            throw new Error("Error copying database");
        }
        database.close();
    }
    /**
     * Copies your database from your local assets-folder to the just created empty database in the
     * system folder, from where it can be accessed and handled.
     * This is done by transfering bytestream.
     * */
    private void copyDataBase(SQLiteDatabase db) throws IOException{
        //Open your local db as the input stream
        InputStream myInput = myContext.getAssets().open(SQL_PATH);
        /*leggo il file*/
        BufferedReader buffread =  new BufferedReader(new InputStreamReader(myInput));
        String line = null;
        while((line = buffread.readLine()) != null) {
            //Log.e("line",""+line);
            //db.execSQL(line);!
            if(!line.equals(new String(""))){
                db.execSQL(line);
            }
        }
        myInput.close();
    }
        public void openDataBase() throws SQLException{
        SQLiteDatabase myDataBase = null;
        String myPath = DATABASE_NAME;
        myDataBase = SQLiteDatabase.openDatabase( DB_PATH+DATABASE_NAME, null, SQLiteDatabase.OPEN_READWRITE);
        Log.e("path",""+myDataBase);
    }
    @Override
    public synchronized void close() {
        /*  if(myDataBase != null)
            myDataBase.close();
         */
        super.close();
    }
    @Override
    public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
        database.execSQL("DROP TABLE IF EXISTS manageZtlStreet;");
        //database.close();
        this.onCreate(database);
    }
    public Cursor getZtlStreet(){
        String query = "select latitude ,longitude from manageZtlstreet";
        SQLiteDatabase rdb = getWritableDatabase();
        /** Cursor cursor=rdb.rawQuery(query,null);
        rdb.close();
        return cursor;*/return null;
    }