2

当我使用 Sqlite 缓存我的数据时,我遇到了这个问题。我已经检查了其他类似的问题但我无法解决。

我的代码是

public int insertByTransaction(List<CacheContent> cacheContentList) {
    android.util.Log.v(com.usher.constants.Constants.TAG_CACHE, "Using transaction to insert records...");
    int count = 0;
    db = getWritableDatabase();
    if (db == null || db.isOpen() == false || cacheContentList == null) {
        return -1;
    }
    // begin transaction
    db.beginTransaction();
    try {
        long result = -1;
        for (CacheContent cacheContent : cacheContentList) {
            ContentValues values = new ContentValues();
            values.put(CacheContent.ID, cacheContent.getId());
            values.put(CacheContent.URL_HASH_CODE, cacheContent.getUrl_hash_code());
            values.put(CacheContent.SERVICE_CONTENT, cacheContent.getService_content());
            values.put(CacheContent.LAST_MODIFIED, cacheContent.getLast_modified());
            values.put(CacheContent.EVENT_BEGIN_TIME, cacheContent.getEvent_start_time());
            result = db.insert(TABLE_NAME, null, values);
            if (result != -1) {
                count++;
            }
        }
        // set Transaction Successful
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // end Transaction
        db.endTransaction();
    }
    return count;
}

而logcat/error信息是

sqlite returned: error code = 1802, msg = statement aborts at 11: [INSERT INTO  .....] Error inserting  
android.database.sqlite.SQLiteDiskIOException: error code 10: disk I/O error
at android.database.sqlite.SQLiteStatement.native_executeInsert(Native Method)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:112)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1737)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1610)
at com.usher.services.DBHelper.insertByTransaction(DBHelper.java:118)
at com.usher.services.ServicesResultCache.addCacheOneByOne(ServicesResultCache.java:293)
at com.usher.services.EventService.doStartService(EventService.java:88)
at com.usher.services.DataServiceImpl$1.call(DataServiceImpl.java:187)
at com.usher.services.DataServiceImpl$1.call(DataServiceImpl.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
at java.lang.Thread.run(Thread.java:1020)
4

0 回答 0