2016-03-25 11 views
2

私のコードは以下の通りです。私はObservable.zipRxJava Androidのリストに各アイテムを追加するには

でcreateListItemを呼び出すしようとしたときに予想されるパラメータと実引数が一致しないというエラーを得た

private Observable<AppointmentListItem> createListItem (Appointment app, Patient patient, Subservice subservice){ 
    AppointmentListItem item = new AppointmentListItem(app.appointment_id, subservice.subservice_name, 
                 patient.patient_fullname, app.appointment_datetime); 
    return Observable.just(item); 
} 

以下のようにヘルパーメソッドで

Observable<List<Appointment>> callAppointments = appointmentServiceRx.appointmentService.getConfirmedAppointments(user_id); 
    callAppointments 
      .flatMapIterable(appointments -> appointments) 
      .flatMap(app -> Observable.zip(
        app, 
        patientServiceRx.patientService.getPatientById(app.patient_id), 
        servicesRestRx.servicesAPIServiceRx.getSubserviceById(app.subservice_id), 
        (appointment, patient, subservice) -> this.createListItem(appointment, patient, subservice) 
      )) 
      .toList() 
      .subscribeOn(Schedulers.io()) 
      .observeOn(AndroidSchedulers.mainThread()) 
      .subscribe(); 

ここにエラーメッセージがあります。

Error message

助けてください.....

答えて

0

Timeline: Activity_idleは赤ニシンであり、あなたの問題には関係ありません。

appointmentのために血まみれのフィールドを使用しているようです!あなたはAppointmentListItemの単一のインスタンスしか持っていません、それが理由です!

編集:Observable::zipはあなたの友人です!私がそれをする方法は次のとおりです。

これは、2つのアポイントの呼び出しを並行して行うという利点があります。 flatMapは必ずしも元の順序を保持しているわけではないので、AppointmentListItemはAppointmentsとは異なる順序で終了することがあります。

+0

ああ、私は参照してください。では、フィールドを使用するのではなく、各結果呼び出しをAppointmentのオブジェクトにどのように取得できますか?なにか提案を? –

+0

元の投稿を編集しました。なぜ私はあなたが 'getService()'呼び出しを使うのか不思議です。なぜ直接サービスを注入しないのですか? –

+0

サービスを直接注入する方法の詳細を教えてください。私はまだこの種のものでは初心者です。 –

関連する問題