RxJava2 UndeliverableException when orientation change is happening while fetching data












1















I get the following error, if I change the orientation of my device while my app is fetching new 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)


That's what the class looks like. Error happens in function 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()
}
}
}


I'm pretty new to RxJava - I'd be really glad if someone can help me with this. Thank you.










share|improve this question




















  • 1





    Have you read the exception message?

    – akarnokd
    Oct 3 '18 at 16:30











  • @akarnokd Yes, I think I understand what the problem is. The exception doesn't reach it's destination. But I don't really understand how to fix it in the context of RxJava. :/

    – myusername
    Oct 3 '18 at 16:34






  • 1





    There is a link in the error message pointing to the wiki to read.

    – akarnokd
    Oct 3 '18 at 16:35






  • 1





    There is an example of that in the wiki section: search for RxJavaPlugins.setErrorHandler.

    – akarnokd
    Oct 3 '18 at 17:07






  • 1





    That's a global handler, define it somewhere early in your application's lifecycle.

    – akarnokd
    Oct 3 '18 at 17:17
















1















I get the following error, if I change the orientation of my device while my app is fetching new 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)


That's what the class looks like. Error happens in function 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()
}
}
}


I'm pretty new to RxJava - I'd be really glad if someone can help me with this. Thank you.










share|improve this question




















  • 1





    Have you read the exception message?

    – akarnokd
    Oct 3 '18 at 16:30











  • @akarnokd Yes, I think I understand what the problem is. The exception doesn't reach it's destination. But I don't really understand how to fix it in the context of RxJava. :/

    – myusername
    Oct 3 '18 at 16:34






  • 1





    There is a link in the error message pointing to the wiki to read.

    – akarnokd
    Oct 3 '18 at 16:35






  • 1





    There is an example of that in the wiki section: search for RxJavaPlugins.setErrorHandler.

    – akarnokd
    Oct 3 '18 at 17:07






  • 1





    That's a global handler, define it somewhere early in your application's lifecycle.

    – akarnokd
    Oct 3 '18 at 17:17














1












1








1








I get the following error, if I change the orientation of my device while my app is fetching new 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)


That's what the class looks like. Error happens in function 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()
}
}
}


I'm pretty new to RxJava - I'd be really glad if someone can help me with this. Thank you.










share|improve this question
















I get the following error, if I change the orientation of my device while my app is fetching new 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)


That's what the class looks like. Error happens in function 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()
}
}
}


I'm pretty new to RxJava - I'd be really glad if someone can help me with this. Thank you.







java android kotlin rx-java2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 3 '18 at 16:36









Mohsen

10.5k42875




10.5k42875










asked Oct 3 '18 at 16:20









myusernamemyusername

9310




9310








  • 1





    Have you read the exception message?

    – akarnokd
    Oct 3 '18 at 16:30











  • @akarnokd Yes, I think I understand what the problem is. The exception doesn't reach it's destination. But I don't really understand how to fix it in the context of RxJava. :/

    – myusername
    Oct 3 '18 at 16:34






  • 1





    There is a link in the error message pointing to the wiki to read.

    – akarnokd
    Oct 3 '18 at 16:35






  • 1





    There is an example of that in the wiki section: search for RxJavaPlugins.setErrorHandler.

    – akarnokd
    Oct 3 '18 at 17:07






  • 1





    That's a global handler, define it somewhere early in your application's lifecycle.

    – akarnokd
    Oct 3 '18 at 17:17














  • 1





    Have you read the exception message?

    – akarnokd
    Oct 3 '18 at 16:30











  • @akarnokd Yes, I think I understand what the problem is. The exception doesn't reach it's destination. But I don't really understand how to fix it in the context of RxJava. :/

    – myusername
    Oct 3 '18 at 16:34






  • 1





    There is a link in the error message pointing to the wiki to read.

    – akarnokd
    Oct 3 '18 at 16:35






  • 1





    There is an example of that in the wiki section: search for RxJavaPlugins.setErrorHandler.

    – akarnokd
    Oct 3 '18 at 17:07






  • 1





    That's a global handler, define it somewhere early in your application's lifecycle.

    – akarnokd
    Oct 3 '18 at 17:17








1




1





Have you read the exception message?

– akarnokd
Oct 3 '18 at 16:30





Have you read the exception message?

– akarnokd
Oct 3 '18 at 16:30













@akarnokd Yes, I think I understand what the problem is. The exception doesn't reach it's destination. But I don't really understand how to fix it in the context of RxJava. :/

– myusername
Oct 3 '18 at 16:34





@akarnokd Yes, I think I understand what the problem is. The exception doesn't reach it's destination. But I don't really understand how to fix it in the context of RxJava. :/

– myusername
Oct 3 '18 at 16:34




1




1





There is a link in the error message pointing to the wiki to read.

– akarnokd
Oct 3 '18 at 16:35





There is a link in the error message pointing to the wiki to read.

– akarnokd
Oct 3 '18 at 16:35




1




1





There is an example of that in the wiki section: search for RxJavaPlugins.setErrorHandler.

– akarnokd
Oct 3 '18 at 17:07





There is an example of that in the wiki section: search for RxJavaPlugins.setErrorHandler.

– akarnokd
Oct 3 '18 at 17:07




1




1





That's a global handler, define it somewhere early in your application's lifecycle.

– akarnokd
Oct 3 '18 at 17:17





That's a global handler, define it somewhere early in your application's lifecycle.

– akarnokd
Oct 3 '18 at 17:17












2 Answers
2






active

oldest

votes


















7














You can override Rx Error Handler with following way:




  1. Extends Application class with your custom MyApplication.


  2. Then write this in onCreate method of your application class:



    @Override
    public void onCreate() {
    super.onCreate();
    RxJavaPlugins.setErrorHandler(throwable -> {}); // nothing or some logging
    }



  3. Add MyApplication class to Manifest:



    <application
    android:name=".MyApplication"
    ...>



For more information, please take a look at RxJava Wiki






share|improve this answer

































    -1














    May be (not tested), there is a possibility to change onError in the Observable with onNext(tag), tag making a difference between "normal onNext" and "error onNext" (replacing the on Error).



    onNext(0) => is due to an Exception (you can get the Exception through a public static String)



    onNext(1) => no error



    emitter.onError(ex); => emitter.onNext(0);



    and in the Observer :



    @Override
    public void onNext(Integer message) {
    if (message ==0 )
    handleError();
    else
    handleNext();
    }


    Of course, it's not very "clean", but it can solve the problem...






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52631581%2frxjava2-undeliverableexception-when-orientation-change-is-happening-while-fetchi%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      7














      You can override Rx Error Handler with following way:




      1. Extends Application class with your custom MyApplication.


      2. Then write this in onCreate method of your application class:



        @Override
        public void onCreate() {
        super.onCreate();
        RxJavaPlugins.setErrorHandler(throwable -> {}); // nothing or some logging
        }



      3. Add MyApplication class to Manifest:



        <application
        android:name=".MyApplication"
        ...>



      For more information, please take a look at RxJava Wiki






      share|improve this answer






























        7














        You can override Rx Error Handler with following way:




        1. Extends Application class with your custom MyApplication.


        2. Then write this in onCreate method of your application class:



          @Override
          public void onCreate() {
          super.onCreate();
          RxJavaPlugins.setErrorHandler(throwable -> {}); // nothing or some logging
          }



        3. Add MyApplication class to Manifest:



          <application
          android:name=".MyApplication"
          ...>



        For more information, please take a look at RxJava Wiki






        share|improve this answer




























          7












          7








          7







          You can override Rx Error Handler with following way:




          1. Extends Application class with your custom MyApplication.


          2. Then write this in onCreate method of your application class:



            @Override
            public void onCreate() {
            super.onCreate();
            RxJavaPlugins.setErrorHandler(throwable -> {}); // nothing or some logging
            }



          3. Add MyApplication class to Manifest:



            <application
            android:name=".MyApplication"
            ...>



          For more information, please take a look at RxJava Wiki






          share|improve this answer















          You can override Rx Error Handler with following way:




          1. Extends Application class with your custom MyApplication.


          2. Then write this in onCreate method of your application class:



            @Override
            public void onCreate() {
            super.onCreate();
            RxJavaPlugins.setErrorHandler(throwable -> {}); // nothing or some logging
            }



          3. Add MyApplication class to Manifest:



            <application
            android:name=".MyApplication"
            ...>



          For more information, please take a look at RxJava Wiki







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 15 '18 at 18:26









          Dr.jacky

          1,59063058




          1,59063058










          answered Oct 3 '18 at 18:04









          DenZapDenZap

          21615




          21615

























              -1














              May be (not tested), there is a possibility to change onError in the Observable with onNext(tag), tag making a difference between "normal onNext" and "error onNext" (replacing the on Error).



              onNext(0) => is due to an Exception (you can get the Exception through a public static String)



              onNext(1) => no error



              emitter.onError(ex); => emitter.onNext(0);



              and in the Observer :



              @Override
              public void onNext(Integer message) {
              if (message ==0 )
              handleError();
              else
              handleNext();
              }


              Of course, it's not very "clean", but it can solve the problem...






              share|improve this answer




























                -1














                May be (not tested), there is a possibility to change onError in the Observable with onNext(tag), tag making a difference between "normal onNext" and "error onNext" (replacing the on Error).



                onNext(0) => is due to an Exception (you can get the Exception through a public static String)



                onNext(1) => no error



                emitter.onError(ex); => emitter.onNext(0);



                and in the Observer :



                @Override
                public void onNext(Integer message) {
                if (message ==0 )
                handleError();
                else
                handleNext();
                }


                Of course, it's not very "clean", but it can solve the problem...






                share|improve this answer


























                  -1












                  -1








                  -1







                  May be (not tested), there is a possibility to change onError in the Observable with onNext(tag), tag making a difference between "normal onNext" and "error onNext" (replacing the on Error).



                  onNext(0) => is due to an Exception (you can get the Exception through a public static String)



                  onNext(1) => no error



                  emitter.onError(ex); => emitter.onNext(0);



                  and in the Observer :



                  @Override
                  public void onNext(Integer message) {
                  if (message ==0 )
                  handleError();
                  else
                  handleNext();
                  }


                  Of course, it's not very "clean", but it can solve the problem...






                  share|improve this answer













                  May be (not tested), there is a possibility to change onError in the Observable with onNext(tag), tag making a difference between "normal onNext" and "error onNext" (replacing the on Error).



                  onNext(0) => is due to an Exception (you can get the Exception through a public static String)



                  onNext(1) => no error



                  emitter.onError(ex); => emitter.onNext(0);



                  and in the Observer :



                  @Override
                  public void onNext(Integer message) {
                  if (message ==0 )
                  handleError();
                  else
                  handleNext();
                  }


                  Of course, it's not very "clean", but it can solve the problem...







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 7:33









                  ChristianChristian

                  322216




                  322216






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52631581%2frxjava2-undeliverableexception-when-orientation-change-is-happening-while-fetchi%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith