唉,为啥那次运行这行就直接抛异常啊
database = SQLiteDatabase.openDatabase(“/mnt/sdcard/dic/dic.db”, null, SQLiteDatabase.OPEN_READWRITE );
很是费解,我是想直接打开/mnt/sdcard/dic/dic.db目录下的数据库文件,权限已经加了,dic.db是通过
if (!(new File(“/mnt/sdcard/dic/dic.db”)).exists()) {
// 获得封装dic.db文件的InputStream对象
InputStream is = this.getResources().openRawResource(R.raw.dic);
FileOutputStream fos = new FileOutputStream(“/mnt/sdcard/dic/dic.db”);
byte[] buffer = new byte[8192];
int count = 0;
// 开始复制dic.db文件
while ((count = is.read(buffer)) > 0) {
fos.write(buffer, 0, count);
}
fos.close();
is.close();
}拷贝到SD卡里的啊

解决方案 »

  1.   

    database = SQLiteDatabase.openDatabase(“/mnt/sdcard/dic/dic.db”, null, SQLiteDatabase.OPEN_READWRITE );
    这一步
    执行完就直接跳到return null;这一行了public SQLiteDatabase SDDB() { SQLiteDatabase database = null;
    try {
    // 获得dic.db文件的绝对路径 String databaseFilename = DATABASE_PATH + "/" + DATABASE_FILENAME;
    // Toast.makeText(getApplicationContext(), databaseFilename,
    // Toast.LENGTH_SHORT).show();
    File dir = new File(DATABASE_PATH);
    // 如果/sdcard/dictionary目录中存在,创建这个目录
    if (!dir.exists())
    dir.mkdir();
    // 如果在/sdcard/dictionary目录中不存在
    // dictionary.db文件,则从res\raw目录中复制这个文件到
    // SD卡的目录(/sdcard/dictionary) if (!(new File(databaseFilename)).exists()) {
    // 获得封装dictionary.db文件的InputStream对象
    InputStream is = this.getResources().openRawResource(R.raw.dic);
    FileOutputStream fos = new FileOutputStream(databaseFilename);
    byte[] buffer = new byte[8192];
    int count = 0;
    // 开始复制dic.db文件
    while ((count = is.read(buffer)) > 0) {
    fos.write(buffer, 0, count);
    }
    fos.close();
    is.close();
    }
    // 打开/sdcard/dictionary目录中的dic.db文件 database =  SQLiteDatabase.openDatabase("/mnt/sdcard/dic/dic.db", null, SQLiteDatabase.OPEN_READWRITE );
    .show();
    return database;
    } catch (Exception e) {
    return null;
    }
      

  2.   

    到return null是说明出异常了,把异常打印出来看下是什么
      

  3.   

    每个应用都拥有自己的sqlite文件,所以调用的时候只需给定db的name就可以了。
      

  4.   

    这个错误找到了,不是在这里,数据库打开了,但调试时候总是会转到Return null这句,很是费解啊!