yigit / android-priority-jobqueue

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.
3.4k stars 395 forks source link

Cannot save job to disk too #430

Open zhujin001032 opened 6 years ago

zhujin001032 commented 6 years ago

Please help me, Thanks! Error message: E/AndroidRuntime: FATAL EXCEPTION: job-manager Process: com.vuspex.contractor.dev, PID: 28302 java.lang.RuntimeException: cannot save job to disk at com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.persistJobToDisk(SqliteJobQueue.java:107) at com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.insert(SqliteJobQueue.java:90) at com.birbit.android.jobqueue.cachedQueue.CachedJobQueue.insert(CachedJobQueue.java:29) at com.birbit.android.jobqueue.JobManagerThread.handleAddJob(JobManagerThread.java:143) at com.birbit.android.jobqueue.JobManagerThread.access$100(JobManagerThread.java:35) at com.birbit.android.jobqueue.JobManagerThread$1.handleMessage(JobManagerThread.java:228) at com.birbit.android.jobqueue.messaging.PriorityMessageQueue.consume(PriorityMessageQueue.java:39) at com.birbit.android.jobqueue.JobManagerThread.run(JobManagerThread.java:222) at java.lang.Thread.run(Thread.java:762) Caused by: java.io.NotSerializableException: com.vuspex.contractor.common.ScheduleInspectionJob$1 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1224) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1584) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1549) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1472) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1218) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) at com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue$JavaSerializer.serialize(SqliteJobQueue.java:493) at com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.persistJobToDisk(SqliteJobQueue.java:105) at com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.insert(SqliteJobQueue.java:90)  at com.birbit.android.jobqueue.cachedQueue.CachedJobQueue.insert(CachedJobQueue.java:29)  at com.birbit.android.jobqueue.JobManagerThread.handleAddJob(JobManagerThread.java:143)  at com.birbit.android.jobqueue.JobManagerThread.access$100(JobManagerThread.java:35)  at com.birbit.android.jobqueue.JobManagerThread$1.handleMessage(JobManagerThread.java:228)  at com.birbit.android.jobqueue.messaging.PriorityMessageQueue.consume(PriorityMessageQueue.java:39)  at com.birbit.android.jobqueue.JobManagerThread.run(JobManagerThread.java:222)  at java.lang.Thread.run(Thread.java:762)  D

This is my Job class:

public class ScheduleInspectionJob extends Job {

transient private Appointments appointments;
transient private String upload_link_secure;
transient private String complete_uri;
transient private String location = "";

transient private ArrayList<PhotoVideo> videoArrayList;
transient private ArrayList<PhotoVideo> photoArrayList;
transient private ArrayList<PhotoVideo> uploadedArrayList;
transient public int photoTotal;
transient public int videoTotal;
transient public int photoFailTotal = 0;
transient public int photoSuccessTotal = 0;
transient public int videoSuccessTotal = 0;
public int appointmentsId;

public ScheduleInspectionJob(int appointmentsId) {
    super(new Params(1).persist().requireNetwork().groupBy("appointments"));
    this.appointmentsId = appointmentsId;
}

@Override
public void onAdded() {
    //job has been secured to disk, add item to database
}

@Override
public void onRun() throws Throwable {
        //query from database
        this.appointments = Appointments.queryAppointmentsWithApId(appointmentsId);
        photoTotal = 0;
        videoTotal = 0;
        photoFailTotal = 0;
        photoSuccessTotal = 0;
        videoSuccessTotal = 0;
        upload_link_secure = "";
        complete_uri = "";
        location = "";

        videoArrayList = new ArrayList<>();
        photoArrayList = new ArrayList<>();
        uploadedArrayList = new ArrayList<>();
        ......... ........

}

kalpeshp0310 commented 6 years ago

This is strange. Do you have any other field in your ScheduleInspectionJob which is not declared as transient other than appointmentsId?

zhujin001032 commented 6 years ago

Thanks for you reply, I'am sure only the appointmentsId filed not declared as transient.

kalpeshp0310 commented 6 years ago

I guess you have anonymous inner class ScheduleInspectionJob $1 in your ScheduleInspectionJob which is not serializable. You can refer this stackoverflow question to investigate more. https://stackoverflow.com/a/32411875/1282812