gpt4 book ai didi

java - 简单的 RxAndroid 代码不起作用

转载 作者:行者123 更新时间:2023-12-02 11:17:19 24 4
gpt4 key购买 nike

我一直在尝试运行这个简单的和平代码,但它不断给出语法错误

这是错误: The error

这是我的代码:

    package com.moein.rx_test

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.internal.operators.flowable.FlowableFlatMap.subscribe
import io.reactivex.schedulers.Schedulers
import org.reactivestreams.Subscriber
import org.reactivestreams.Subscription


class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

Observable.just("Hello World")
.subscribeOn(Schedulers.newThread())
//each subscription is going to be on a new thread.
.observeOn(AndroidSchedulers.mainThread())
//observation on the main thread
//Now our subscriber!
.subscribe(object: Subscriber<String>(){
override fun onComplete() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onSubscribe(s: Subscription?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onError(e: Throwable?) {
//TODO : Handle error here
}

override fun onNext(t: String?) {
Log.e("Output",t);
}
})

}
}

我在导入订阅时尝试了所有这些库 libraries

我该如何解决这个问题?

最佳答案

Observable 的默认消费者类型是 Observer:

.subscribe(object: Observer<String>(){
override fun onComplete() {
TODO("not implemented")
}

override fun onSubscribe(s: Disposable?) {
TODO("not implemented")
}

override fun onError(e: Throwable?) {
//TODO : Handle error here
}

override fun onNext(t: String?) {
Log.e("Output",t);
}
})

关于java - 简单的 RxAndroid 代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50181837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com