简体   繁体   English

android Rx-java + Retrofit2错误与Kotlin

[英]android Rx-java + Retrofit2 error with Kotlin

I am trying to build an android app with MVVM pattern. 我正在尝试使用MVVM模式构建一个Android应用程序。

Everything is good except rx-java part. 除了rx-java部分之外,其他一切都很好。

Using Observer in subscribe, I have got an error like this. 在订阅中使用Observer时,出现这样的错误。

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. 谢谢。

It looks like your observer is Observer<List<Flyer>> but you need an Observer<Flyer> . 看来您的观察者是Observer<List<Flyer>>但您需要一个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> 可能想将观察者重做为Observer<Flyer>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM