第一次使用适用于 Android 的 Google Tasks API 并遇到此问题:使用 Tasks.whenAllComplete 或 .whenAllSuccess() 和 OnCompleteListener 或 OnSuccessListener 我收到错误 Task is not yet complete 即使我检查 task.isComplete() 和它返回真。知道这里出了什么问题吗?
db.collection("calendar").get()
.continueWith(new Continuation<Task<QuerySnapshot>, Task<?>>() {
@Override
public Task<?> then(@NonNull Task<Task<QuerySnapshot>> task) throws Exception {
List<Task<QuerySnapshot>> tasks = new ArrayList<Task<QuerySnapshot>>();
for (DocumentSnapshot ds : task.getResult().getResult())
tasks.add(ds.getReference().collection("thingstodo").get());
return Tasks.whenAllSuccess(tasks);
}
})
.addOnCompleteListener(new OnCompleteListener<Task<?>>() {
@Override
public void onComplete(@NonNull Task<Task<?>> task) {
List<QuerySnapshot> lists = (ArrayList<QuerySnapshot>)task.getResult().getResult(); //error in this line
for (QuerySnapshot qs : lists)
for (DocumentSnapshot ds: qs) {
ScheduledItem item = ds.toObject(ScheduledItem.class);
//add to list including day
itemsList.add(item);
}
//list ready to be used!
}
});
这是错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tripjoe.tripjoe, PID: 6161
java.lang.IllegalStateException: Task is not yet complete
at com.google.android.gms.common.internal.zzbq.zza(Unknown Source:8)
at com.google.android.gms.tasks.zzn.zzbjk(Unknown Source:5)
at com.google.android.gms.tasks.zzn.getResult(Unknown Source:3)
at com.tripjoe.tripjoe.services.Wizard$4.onSuccess(Wizard.java:74)
at com.tripjoe.tripjoe.services.Wizard$4.onSuccess(Wizard.java:71)
at com.google.android.gms.tasks.zzj.run(Unknown Source:27)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)