Android 打开sqlite时,会出现异常

Android 打开sqlite时,会出现异常,android,sqlite,Android,Sqlite,我在android应用程序中创建了数据库,然后插入了一条语句。一切都正常,所以我想从我的_包/databases/中获取我的数据库,并将其复制到sd卡以便访问 这是可行的,但当我尝试使用我的sqlite Firefox插件打开时,出现以下错误: SQLiteManager: Error in opening file Datas.sqlite - either the file is encrypted or corrupt Exception Name: NS_ERROR_FILE_CORRU

我在android应用程序中创建了数据库,然后插入了一条语句。一切都正常,所以我想从我的_包/databases/中获取我的数据库,并将其复制到sd卡以便访问

这是可行的,但当我尝试使用我的sqlite Firefox插件打开时,出现以下错误:

SQLiteManager: Error in opening file Datas.sqlite - either the file is encrypted or corrupt
Exception Name: NS_ERROR_FILE_CORRUPTED
Exception Message: Component returned failure code: 0x8052000b (NS_ERROR_FILE_CORRUPTED) [mozIStorageService.openUnsharedDatabase] 
也许我必须用别的东西打开,或者我不能这么容易打开这个

我将给出我使用的所有代码:

处理我的数据库时,我使用了以下所有代码:

将其复制到sd卡此方法:

public static boolean backUpDataBase(Context context) {

        final String DATABASE_NAME = "Data.sqlite";
        final String DATABASE_NAME_FULL = "/data/data/package/databases/"
                + DATABASE_NAME;
        boolean result = true;

        // Source path in the application database folder
        String appDbPath = DATABASE_NAME_FULL;

        // Destination Path to the sdcard app folder
        String sdFolder = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + "/" + "Datas.sqlite";

        File f = new File(sdFolder);
        // if (!f.exists()) {
        // f.mkdir();
        // }

        InputStream myInput = null;
        OutputStream myOutput = null;
        try {
            // Open your local db as the input stream
            myInput = new FileInputStream(appDbPath);
            // Open the empty db as the output stream
            myOutput = new FileOutputStream(f);

            // 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);
            }
        } catch (IOException e) {
            result = false;
            e.printStackTrace();
        } finally {
            try {
                // Close the streams
                if (myOutput != null) {
                    myOutput.flush();
                    myOutput.close();
                }
                if (myInput != null) {
                    myInput.close();
                }
            } catch (IOException e) {
            }
        }

        return result;
    }
我的数据库如下所示: 2个表:

CREATE TABLE "Test" ("_id" INTEGER PRIMARY KEY  NOT NULL  UNIQUE , "Info" TEXT)

CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US')
和代码来完成我需要的一切:

//返回读写数据库 DataBaseHelper dataBase=Main.createorOpenBMContext

        Main.backUpDataBase(mContext);

        db = dataBase.myDataBase;

        // Step 1: Inflate layout
        setContentView(R.layout.tabs_fragment_activity);

        try{
        db.execSQL("INSERT INTO " +"Test" +" Values ('1','Inserted');");
        }catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }

那么,insert工作正常,哪里出了问题呢?

听起来您的代码在将其写入SD卡时出现了问题,但我没有立即看到

我想知道,你为什么要把它复制到SD卡上?听起来你只是想检查一下文件

如果这确实是您的目标,那么我建议您运行emulator,只需使用eclipse中的DDMS视图,导航到该文件并单击右上角的按钮,其工具提示显示从设备中拉出文件。你在模拟器中得到的应该和你在手机上得到的完全一样。

试着使用