2012-12-17 45 views
2

我寫了一些用於刪除數據庫文件夾的代碼。它刪除數據庫,但也拋出錯誤。請告訴我如何解決這個問題。android.database.sqlite.SQLiteDiskIOException:磁盤I/O錯誤(代碼1802)

代碼刪除數據庫

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) 
+0

它不是該數據庫刪除導致的問題,它是moveToFirst通話 – nandeesh

+0

這個功能可能是有益的https://stackoverflow.com/questions/44312563/sqlitediskioexception-disk-io-error-code-1802-while-compiling-pragma-jou ​​/ 45329480#45329480 –

回答

7

你應該之前關閉遊標和數據庫刪除SQLite的文件。

+0

謝謝你的回覆@Sam你能告訴我如何解決這個問題 – Dilip

+0

好吧,讓我們從頭開始。錯誤可能從這裏開始:'at com.zengamedia.ui.Splash $ 1.run(Splash.java:51)'。第71行是什麼?在你的問題中發佈'run()'。 – Sam

+0

看上面plj \ – Dilip

0

錯誤代碼1802是SQLITE_IOERR_FSTAT。我寧願假設磁盤級別有問題,嘗試刪除數據庫並檢查磁盤介質。

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)); 
     } 
    }