- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如果我在我的应用程序获取新的 redditNews 时更改设备的方向,我会收到以下错误。
E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadScheduler-1
Process: com.spicywdev.schmeddit, PID: 26522
io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | null
at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.onError(ObservableCreate.java:73)
at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:43)
at io.reactivex.Observable.subscribe(Observable.java:12090)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Caused by: java.io.InterruptedIOException
at okhttp3.internal.http2.Http2Stream.waitForIo(Http2Stream.java:579)
at okhttp3.internal.http2.Http2Stream.takeResponseHeaders(Http2Stream.java:143)
at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:125)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:91)
at com.spicywdev.schmeddit.features.news.NewsManager$getNews$1.subscribe(NewsManager.kt:16)
at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)
这就是类的样子。函数 requestNews()
发生错误。
class NewsFragment : RxBaseFragment() {
companion object {
private val KEY_REDDIT_NEWS = "redditNews"
}
private var redditNews: RedditNews? = null
private val newsManager by lazy { NewsManager() }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return container?.inflate(R.layout.news_fragment)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
news_list.apply {
setHasFixedSize(true)
val linearLayoutManager = LinearLayoutManager(context)
layoutManager = linearLayoutManager
clearOnScrollListeners()
addOnScrollListener(InfiniteScrollListener({ requestNews()}, linearLayoutManager))
}
initAdapter()
if (savedInstanceState != null && savedInstanceState.containsKey(KEY_REDDIT_NEWS)) {
redditNews = savedInstanceState.get(KEY_REDDIT_NEWS) as RedditNews
(news_list.adapter as NewsAdapter).clearAndAddNews(redditNews!!.news)
} else {
requestNews()
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
val news = (news_list.adapter as NewsAdapter).getNews()
if (redditNews != null && news.isNotEmpty()) {
outState.putParcelable(KEY_REDDIT_NEWS, redditNews?.copy(news = news))
}
}
private fun requestNews() {
/**
* first time will send empty string for after parameter.
* Next time we will have redditNews set with the next page to
* navigate with the after param.
*/
val subscription = newsManager.getNews(redditNews?.after ?: "")
.subscribeOn(Schedulers.io())
.subscribe(
{
retrievedNews ->
redditNews = retrievedNews
(news_list.adapter as NewsAdapter).addNews(retrievedNews.news)
},
{
e -> Snackbar.make(news_list, e.message ?: "WZF", Snackbar.LENGTH_LONG).show()
}
)
subscriptions.add(subscription)
}
private fun initAdapter() {
if (news_list.adapter == null) {
news_list.adapter = NewsAdapter()
}
}
}
我是 RxJava 的新手 - 如果有人可以帮助我,我将非常高兴。谢谢你。
最佳答案
您可以通过以下方式覆盖 Rx 错误处理程序:
然后在您的应用程序类的 onCreate 方法中写入:
@Override
public void onCreate() {
super.onCreate();
RxJavaPlugins.setErrorHandler(throwable -> {}); // nothing or some logging
}
将 MyApplication 类添加到 list :
<application
android:name=".MyApplication"
...>
更多信息,请查看RxJava Wiki
关于java - 获取数据时发生方向更改时的 RxJava2 UndeliverableException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52631581/
如果我在我的应用程序获取新的 redditNews 时更改设备的方向,我会收到以下错误。 E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadSche
我的 fragment 中有一个如下所示的可观察链。我有一个微调器,它会在项目选择时触发 Subject,并且根据选择,我正在使用 Picasso 在 Schedulers.computation()
我的应用程序在 Crashlytics(Fabric) 上反复出现异常。我使用带有改造的 rxjava2 来进行我的 http 调用。 这就是 crashlytics 日志中的所有内容(如下)。将不胜
虽然其中一个 Rails 发出了 onError(),但另一个 Rails 中的 isCancelled() 仍然返回 false,这导致了 UndeliverableException >。如何检查
据我了解,RxJava2 values.take(1) 创建了另一个 Observable,它只包含原始 Observable 中的一个元素。 MUST NOT 抛出异常,因为它被 take(1) 的
我在存储库中有这样的代码: return Completable.fromAction { // Some code loginService.login(id) .s
我使用RxJava和Retrofit进行网络请求,但偶尔会收到错误反馈。在ApiManager.java:216是我添加常用参数的方法。 错误信息: io.reactivex.exceptions.U
使用 completable 时出现 UndeliverableException public Completable createBucketWithStorageClassAndLocation
我是一名优秀的程序员,十分优秀!