ms nornen
ms nornen

Reputation: 3

android Rx-java + Retrofit2 error with Kotlin

I am trying to build an android app with MVVM pattern.

Everything is good except rx-java part.

Using Observer in subscribe, I have got an error like this.

Error:(28, 18) None of the following functions can be called with the arguments supplied:
public final fun subscribe(p0: ((Flyer!) -> Unit)!): Subscription! defined in rx.Observable
public final fun subscribe(p0: Observer<in Flyer!>!): Subscription! defined in rx.Observable
public final fun subscribe(p0: Subscriber<in Flyer!>!): Subscription! defined in rx.Observable
public final fun subscribe(p0: Action1<in Flyer!>!): Subscription! defined in rx.Observable

My code

override fun getflyers(observer: Observer<List<Flyer>>) {
        homeService.flyer(createMap())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer) // error here
    }

Any ideas for me?

Thank you.

Upvotes: 0

Views: 254

Answers (1)

cwbowron
cwbowron

Reputation: 1025

It looks like your observer is Observer<List<Flyer>> but you need an Observer<Flyer>. The service is emitting Flyers and your observer is looking for lists of them. Probably want to redo your observer as Observer<Flyer>

Upvotes: 1

Related Questions