Path JobQueue无法序列化String HashSet

时间:2015-11-14 18:59:12

标签: java android priority-queue job-queue

我需要为JobQueue序列化一系列字符串。我怎么做?使用HashSet<String>会导致异常。我正在使用https://github.com/path/android-priority-jobqueue(此处没有标签)

error while serializing object PersistNotificationSettingsJob
 java.io.NotSerializableException: com.mycompanyandroid.Application
     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
     at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
     at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
     at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
     at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
     at com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue$JavaSerializer.serialize(SqliteJobQueue.java:347)
     at com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.safeSerialize(SqliteJobQueue.java:324)
     at com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.getSerializeBaseJob(SqliteJobQueue.java:319)
     at com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.bindValues(SqliteJobQueue.java:75)
     at com.path.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.insert(SqliteJobQueue.java:59)
     at com.path.android.jobqueue.cachedQueue.CachedJobQueue.insert(CachedJobQueue.java:26)
     at com.path.android.jobqueue.JobManager.addJob(JobManager.java:499)
     at com.path.android.jobqueue.JobManager$4.run(JobManager.java:565)
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
     at java.lang.Thread.run(Thread.java:818)

1 个答案:

答案 0 :(得分:1)

您正在尝试序列化不可序列化的Application类。 让它变得短暂,并在你的工作运行时从某个地方获取。您也可以从job#getApplicationContext获取。 http://yigit.github.io/android-priority-jobqueue/javadoc/index.html