android.database.sqlite.SQLiteDiskIOException:仅在首次运行时出现磁盘I / O错误

时间:2015-06-15 05:00:46

标签: android orm activeandroid

App正确运行并创建数据库和表,但是当我尝试保存模型时,我得到了这个例外。 但是当应用崩溃时和我relunch the app时,error doesn't happen anymore!和saves and loads models very well

Application类上初始化activeandroid:

@Override
public void onCreate() {
    super.onCreate();
    ActiveAndroid.initialize(this);

模特课:

@Table(name = "history_records")
public class HistoryRecord extends Model {

public static final String COST = "cost";
public static final String REMOTE_ID = "remoteId";
public static final String OWNER_ID = "ownerId";
public static final String DURATION = "duration";
public static final String DATE = "date";
public static final String TO_NUMBER = "to_number";
public static final String FROM_NUMBER = "from_number";
public static final String SESSION = "session";
// Stores this record's position in tab
@Column(index = true)
public String tab;

@Column(name = COST)
@Expose
@SerializedName("cost")
public float cost;

@Column(name = REMOTE_ID, index = true)
@Expose
@SerializedName("id")
public String remoteId;

@Column(name = OWNER_ID)
@Expose
@SerializedName("owner_id")
public String ownerId;

@Column(name = SESSION)
@Expose
@SerializedName("session")
public String session;

@Column(name = FROM_NUMBER)
@Expose
@SerializedName("from")
public String from;

@Column(name = TO_NUMBER)
@Expose
@SerializedName("to")
public String to;

@Column(name = DATE)
@Expose
@SerializedName("date")
public String date;


@Column(name = DURATION)
@Expose
@SerializedName("duration")
public int duration;

@Expose
@SerializedName("track")
public List<Track> tracks;

public HistoryRecord() {
    super();
    tracks = new ArrayList<>();
}

public List<Track> getTracks() {
    return getMany(Track.class, "history_record");
}
}

这是我的保存代码:

ActiveAndroid.beginTransaction();
            try {
                for (HistoryRecord hr : records) {
                    hr.tab = tabNumber;
                    hr.save();
                    for (int i = 0, tracksSize = hr.tracks.size(); i < tracksSize; i++) {
                        hr.tracks.get(i).historyRecord = hr;
                        hr.tracks.get(i).data.track = hr.tracks.get(i);
                        hr.tracks.get(i).save();
                        hr.tracks.get(i).data.save();
                    }
                }
                ActiveAndroid.setTransactionSuccessful();
            } catch (Exception e) {

            } finally {
                ActiveAndroid.endTransaction();
            }

堆栈追踪:

06-15 00:14:50.467  18409-18409/ E/SQLiteDatabase﹕ Error inserting from_number=+266696687 duration=5 session=f16a90e3-3ba7-4941-878b-22cb103a54b3 ownerId=ca0c96715b843fa0b35b57118a00191c to_number=16699990089 tab=all remoteId=b3db24018f977af5a1e63badc301ec2c Id=null date=2015-03-16 09:34:21 cost=0.15
android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1802)
        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782)
        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
        at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
        at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
        at com.activeandroid.Model.save(Model.java:155)
        at .model.HistoryRecordProvider$1.run(HistoryRecordProvider.java:65)
        at .model.HistoryRecordProvider.saveHistoryRecord(HistoryRecordProvider.java:73)
        at .model.HistoryRecordProvider.insert(HistoryRecordProvider.java:148)
        at .view.fragment.CallLogFragmentAll$2.success(CallLogFragmentAll.java:114)
        at .view.fragment.CallLogFragmentAll$2.success(CallLogFragmentAll.java:107)
        at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案