android.database.sqlite.SQLiteDiskIOException:磁盘I / O错误(代码1802)

时间:2012-12-17 07:32:47

标签: android database

我编写了一些用于删除数据库文件夹的代码。它删除数据库但也抛出错误。请建议我如何解决这个问题。

删除数据库代码

public void deleteDB() {
        try {
            File db_path = new File(
                    "/data/data/pacakge_name/databases/mydatabase_db.db");
            db_path.delete();
            System.out
                    .println("Database deleted successfully================================");
        } catch (Exception e) {
            // TODO: handle exception
            Log.e("Error==", e.toString());
        }
    }
Cursor cursor = handler.getCategoryData("1");
                        if (cursor.moveToFirst()) {
                            System.out
                                    .println("database has data................................");
                        } else {
                            System.out
                                    .println("database has no data.............................");
                            LiveTVCategoryParser category_parser = new LiveTVCategoryParser();
                            category_parser.category_parser(Splash.this, "1",
                                    "live_root");
                        }

错误:

android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1802)
E/AndroidRuntime(  613):    at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
E/AndroidRuntime(  613):    at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:838)
E/AndroidRuntime(  613):    at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
E/AndroidRuntime(  613):    at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
E/AndroidRuntime(  613):    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
E/AndroidRuntime(  613):    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
E/AndroidRuntime(  613):    at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:196)
E/AndroidRuntime(  613):    at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:236)
E/AndroidRuntime(  613):    at com.zengamedia.ui.Splash$1.run(Splash.java:51)
E/AndroidRuntime(  613):    at java.util.Timer$TimerImpl.run(Timer.java:284)

3 个答案:

答案 0 :(得分:7)

在删除SQLite文件之前,您应该关闭游标和数据库

答案 1 :(得分:0)

错误代码1802是SQLITE_IOERR_FSTAT。我宁愿假设磁盘级别出现问题,请尝试删除数据库并检查磁盘介质。

答案 2 :(得分:0)

在数据库的CRUD

时调用此函数
public synchronized void checkDBIsOpen() {
        try {
            mydb = dbHelper.getWritableDatabase();
        } catch (Exception e) {
            e.printStackTrace();
            NewsLog.error(TAG, "check database is open or not,excetpion:" + Utility2_1.getErrorInfo(e));
        }
    }