I'm trying to handle errors in Rx android networking but unable to do so can some help.
getCompositeDisposable().add(getManager().callApi(request)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.ui())
.subscribe(apiResponse -> Log.d(TAG,"success"),
throwable -> Log.e(TAG,throwable.getMessage)));
I want to handle errors in subscribe()
Logs:
io.reactivex.exceptions.OnErrorNotImplementedException: java.net.ConnectException: Failed to connect
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
at io.reactivex.internal.observers.ConsumerSingleObserver.onError(ConsumerSingleObserver.java:47)
at io.reactivex.internal.operators.single.SingleObserveOn$ObserveOnSingleObserver.run(SingleObserveOn.java:79)
at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: com.androidnetworking.error.ANError: java.net.ConnectException: Failed to connect to /192.168.1.42:8484
at com.rx2androidnetworking.Rx2InternalNetworking$SimpleANObservable.subscribeActual(Rx2InternalNetworking.java:235)
at io.reactivex.Observable.subscribe(Observable.java:10981)
at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
at io.reactivex.Single.subscribe(Single.java:2801)
at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
Unfortunately i can not comment. Could you be more specific? What error have you got? The common way to handle errors using rx looks like this:
Subscription subscribe = apiServices.endpointCall(...parameters...)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.unsubscribeOn(Schedulers.io());
.subscribe(response -> {
//do something with response
}, throwable -> {
//do something with error
});
Where apiService is created by retrofit using
service = retrofit.create(ApiServices.class);
Related
I am getting an error the first time the user sign in, however, there is no error the second time the user open the app
from the logcat the awaiClose function is triggered. so where is the error come from?!
The code
val userIdFlow = callbackFlow {
val listener = FirebaseAuth.AuthStateListener { firebaseAuth ->
Timber.tag("Auth_Util").d("Changed")
firebaseAuth.currentUser?.let {
Timber.tag("Auth_Util").d("user exist, id = ${it.uid}")
trySend(it.uid) // the line mentioned in the error message (AuthUtil.kt:38)
}
}
auth.addAuthStateListener(listener)
awaitClose {
Timber.tag("Auth_Util").d("Closed")
auth.removeAuthStateListener(listener)
}
}
The Logcat
2022-10-13 16:00:11.541 6972-6972 Auth_Util com.hussienFahmy.myGpaManager D Changed
2022-10-13 16:00:11.541 6972-6972 Auth_Util com.hussienFahmy.myGpaManager D user exist, id = g11Hbz2EUWXGSE0WnbcF2nJRUPQ2
2022-10-13 16:00:11.543 6972-6972 Auth_Util com.hussienFahmy.myGpaManager D Closed
2022-10-13 16:00:11.716 6972-6972 AndroidRuntime com.hussienFahmy.myGpaManager E FATAL EXCEPTION: main
Process: com.hussienFahmy.myGpaManager, PID: 6972
java.lang.IllegalStateException: 'awaitClose { yourCallbackOrListener.cancel() }' should be used in the end of callbackFlow block.
Otherwise, a callback/listener may leak in case of external cancellation.
See callbackFlow API documentation for the details.
at kotlinx.coroutines.flow.CallbackFlowBuilder.collectTo(Builders.kt:343)
at kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1.invokeSuspend(ChannelFlow.kt:60)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:245)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuationImpl.kt:513)
at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.completeResumeReceive(AbstractChannel.kt:908)
at kotlinx.coroutines.channels.ArrayChannel.offerInternal(ArrayChannel.kt:83)
at kotlinx.coroutines.channels.AbstractSendChannel.trySend-JP2dKIU(AbstractChannel.kt:155)
at kotlinx.coroutines.channels.ChannelCoroutine.trySend-JP2dKIU(Unknown Source:2)
at com.hussienFahmy.myGpaManager.network.AuthUtil$userIdFlow$1.invokeSuspend$lambda-1(AuthUtil.kt:38)
at com.hussienFahmy.myGpaManager.network.AuthUtil$userIdFlow$1.$r8$lambda$gz_nO4N2PXNldWwFNxezrd-NGHg(Unknown Source:0)
at com.hussienFahmy.myGpaManager.network.AuthUtil$userIdFlow$1$$ExternalSyntheticLambda0.onAuthStateChanged(Unknown Source:2)
at com.google.firebase.auth.zzk.run(com.google.firebase:firebase-auth##21.0.8:1)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8057)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}#1daddb6, Dispatchers.Main.immediate]
I have created a Firebase project and add google-services.json to app module.
I have setup Firebase remote config as follow :
private fun initFirebaseRemoteConfig() {
val remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
minimumFetchIntervalInSeconds = if (BuildConfig.DEBUG) 0 else 3600
}
//remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
remoteConfig.setConfigSettingsAsync(configSettings)
remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
val updated = task.result
if (task.isSuccessful) {
Timber.d("Config params updated: $updated")
} else {
Timber.d("Unsuccessful")
}
}
}
I receive following exception on this line task.result as follow :
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException: Fetch failed: The user is not authorized to access the project. Please make sure you are using the API key that corresponds to your Firebase project.
at com.google.android.gms.tasks.zzu.getResult(com.google.android.gms:play-services-tasks##17.0.2:15)
at com.sample.android.tmdb.TmdbApp.initFirebaseRemoteConfig$lambda-0(TmdbApp.kt:34)
at com.sample.android.tmdb.TmdbApp.lambda$P4-jkzwf9-IJZ17_EtnpghkBXis(Unknown Source:0)
at com.sample.android.tmdb.-$$Lambda$TmdbApp$P4-jkzwf9-IJZ17_EtnpghkBXis.onComplete(Unknown Source:0)
at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks##17.0.2:4)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.google.android.gms.internal.tasks.zzb.dispatchMessage(com.google.android.gms:play-services-tasks##17.0.2:6)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException: Fetch failed: The user is not authorized to access the project. Please make sure you are using the API key that corresponds to your Firebase project.
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.createExceptionWithGenericMessage(ConfigFetchHandler.java:380)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackend(ConfigFetchHandler.java:333)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackendAndCacheResponse(ConfigFetchHandler.java:278)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.lambda$fetchIfCacheExpiredAndNotThrottled$1$ConfigFetchHandler(ConfigFetchHandler.java:215)
at com.google.firebase.remoteconfig.internal.-$$Lambda$ConfigFetchHandler$PAoFtfQiOtbXSTeK4H2aFJ-JNJI.then(Unknown Source:8)
at com.google.android.gms.tasks.zzg.run(com.google.android.gms:play-services-tasks##17.0.2:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Caused by: com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException: Forbidden
at com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient.fetch(ConfigFetchHttpClient.java:195)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackend(ConfigFetchHandler.java:307)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackendAndCacheResponse(ConfigFetchHandler.java:278)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.lambda$fetchIfCacheExpiredAndNotThrottled$1$ConfigFetchHandler(ConfigFetchHandler.java:215)
at com.google.firebase.remoteconfig.internal.-$$Lambda$ConfigFetchHandler$PAoFtfQiOtbXSTeK4H2aFJ-JNJI.then(Unknown Source:8)
at com.google.android.gms.tasks.zzg.run(com.google.android.gms:play-services-tasks##17.0.2:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
I was trying to make an API request inside a Kotlin Coroutines. I have wrapped all code inside the coroutine with a try-catch block.
viewModelScope.launch {
try {
val temp = repository.searchMatch(query ?: "")
liveData.postValue(temp)
} catch (e: Exception) {
Log.d(TAG, e.message.toString())
}
}
The problem is, if I turning off the network while the request still running, the exception gets caught but also my app gets crashed because of the uncaught exception.
This is the uncaught exception I got:
android.system.ErrnoException: read failed: ENETDOWN (Network is down)
at libcore.io.Linux.readBytes(Native Method)
at libcore.io.Linux.read(Linux.java:184)
at libcore.io.BlockGuardOs.read(BlockGuardOs.java:254)
at android.system.Os.read(Os.java:414)
at android.net.util.PacketReader.readPacket(PacketReader.java:137)
at android.net.util.PacketReader.handleInput(PacketReader.java:207)
at android.net.util.PacketReader.access$100(PacketReader.java:70)
at android.net.util.PacketReader$1.onFileDescriptorEvents(PacketReader.java:189)
at android.os.MessageQueue.dispatchEvents(MessageQueue.java:285)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:165)
at android.os.HandlerThread.run(HandlerThread.java:65)
2020-08-13 23:48:49.326 1205-5265/? E/MtkDhcpClient: Read error
android.system.ErrnoException: read failed: ENETDOWN (Network is down)
at libcore.io.Linux.readBytes(Native Method)
at libcore.io.Linux.read(Linux.java:184)
at libcore.io.BlockGuardOs.read(BlockGuardOs.java:254)
at android.system.Os.read(Os.java:414)
at com.mediatek.net.dhcp.MtkDhcpClient$ReceiveThread.run(MtkDhcpClient.java:434)
I have tried to set a CoroutineExceptionHandler and use a SupervisorJob but nothing works.
Please help me!
W/System.err: java.net.UnknownHostException: Unable to resolve host "api.rawg.io": No address associated with hostname
W/System.err: at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at okhttp3.Dns$1.lookup(Dns.java:40)
at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:185)
at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:149)
at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:214)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
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)
W/System.err: 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)
W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
at okhttp3.RealCall.execute(RealCall.java:92)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:186)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:45)
at io.reactivex.Observable.subscribe(Observable.java:10838)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
at io.reactivex.Observable.subscribe(Observable.java:10838)
at io.reactivex.internal.operators.flowable.FlowableFromObservable.subscribeActual(FlowableFromObservable.java:29)
at io.reactivex.Flowable.subscribe(Flowable.java:12978)
at io.reactivex.internal.operators.flowable.FlowableOnBackpressureLatest.subscribeActual(FlowableOnBackpressureLatest.java:32)
at io.reactivex.Flowable.subscribe(Flowable.java:12978)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach.subscribeActual(FlowableDoOnEach.java:50)
at io.reactivex.Flowable.subscribe(Flowable.java:12978)
at io.reactivex.Flowable.subscribe(Flowable.java:12924)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:929)
W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
W/System.err: at libcore.io.Linux.android_getaddrinfo(Native Method)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:200)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
... 43 more
When application have connection with internet working good but when i have no internet connection my application crash. I want to handle this Exception but anything what i tried not helped :/ . I tried too check if source is not null . I am using Dagger 2 , Retrofit 2, RxJava, viewModel .
class VideoViewModel : ViewModel {
private val authApi: AuthApi
private val games: MediatorLiveData<TopGames> = MediatorLiveData<TopGames>()
#Inject
constructor(authApis: AuthApi) {
authApi = authApis
}
fun authenticateWithId(dates: String) {
val source: LiveData<TopGames> = LiveDataReactiveStreams.fromPublisher(
authApi.getTopGames(dates, "-added").doOnError { t-> print("${t.printStackTrace()} doOnError") }
.subscribeOn(Schedulers.io())
)
games.addSource<TopGames>(source, object : androidx.lifecycle.Observer<TopGames?> {
override fun onChanged(t: TopGames?) {
// Log.d("TAG", "VideoonChanged: $t")
games.value = t
games.removeSource(source)
}
})
}
fun observeGaneInfo(): LiveData<TopGames?>? {
return games
}
}
Other class
interface AuthApi {
#GET("/api/games")
fun getTopGames(
#Query("dates") dates: String,
#Query("ordering") ordering: String
): Flowable<TopGames>
}
There is no error handling in your rx chain. So you might to want to do something like this.
val source: LiveData<TopGames> = LiveDataReactiveStreams.fromPublisher(
authApi.getTopGames(dates, "-added")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
games.value = it
},
{
// error handling goes here
}
)
)
You can have separate LiveData for your error messages, but the more cleaner approach would be to create State class, as mentioned in other replies, so you only have the single source of view state updates.
Also please note that the Disposable return from subscribe method is better to be disposed on ViewModel's onCleared method.
Solution :
create data class on State
data class DataWithStates<T>(
val data: T? = null,
val states: Throwable? = null
)
and in my live data i change val source: LiveData to LiveData<DataWithStates> and work perfectly
fun authenticateWithId(dates: String) {
val source: LiveData<DataWithStates<TopGames>> = LiveDataReactiveStreams.fromPublisher(
authApi.getTopGames(dates, "-added").map { lstUser -> DataWithStates(lstUser) }.onErrorReturn { ex -> DataWithStates(states = ex) }
.subscribeOn(Schedulers.io())
)
games.addSource<DataWithStates<TopGames>>(source, object : androidx.lifecycle.Observer<DataWithStates<TopGames>> {
override fun onChanged(t: DataWithStates<TopGames>) {
// Log.d("TAG", "VideoonChanged: $t")
games.value = t.data
games.removeSource(source)
}
})
}
helpful Link
RxJava to live data error Handling
I need to get data from Api for each list element also I need to implement Internet connection checker.
Then program starts everything works great.
I disable Internet on live, and run method again (using swipeRefreshLayout), I receive InternetErrorToast, great!
I restored Internet on live, and run method again (using swipeRefreshLayout), app crashed with error.
Now I have following method.
Note! dataManager.getCityConditionsResponse() return Single
#Override
public void updateCitiesList() {
List<City> citiesList = dataManager.getCitiesFromDb();
if (!dataManager.isInternetConnected()) {
view.showCitiesList(citiesList);
view.showInternetErrorToast();
} else {
compositeDisposable.add(Observable.fromIterable(citiesList)
.doOnNext(city -> dataManager.getCityConditionsResponse(city.getQuery())
.subscribe(
response -> {
city.setTemp(response.getTemp());
city.setIcon(response.getIcon());
},
error -> view.showServerErrorToast()))
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
list -> view.showCitiesList(list),
error -> view.showServerErrorToast()
));
}
view.hideRefreshingStatus();
}
On step 3 I have this error
018-10-12 16:34:54.033 19013-19046/mike.weather E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadScheduler-1
Process: mike.weather, PID: 19013
io.reactivex.exceptions.CompositeException: 2 exceptions occurred.
at io.reactivex.internal.observers.ConsumerSingleObserver.onError(ConsumerSingleObserver.java:49)
at io.reactivex.internal.operators.observable.ObservableSingleSingle$SingleElementObserver.onError(ObservableSingleSingle.java:93)
at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onError(BodyObservable.java:72)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:56)
at io.reactivex.Observable.subscribe(Observable.java:12090)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
at io.reactivex.Observable.subscribe(Observable.java:12090)
at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
at io.reactivex.Single.subscribe(Single.java:3438)
at io.reactivex.Single.subscribe(Single.java:3424)
at mike.weather.ui.main.MainActivityPresenter.lambda$updateCitiesList$3(MainActivityPresenter.java:49)
at mike.weather.ui.main.-$$Lambda$MainActivityPresenter$UqLPaAef0SB9PT-Rz654tgX3dnA.accept(Unknown Source:4)
at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onNext(ObservableDoOnEach.java:93)
at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onNext(ObservableDoOnEach.java:101)
at io.reactivex.internal.operators.observable.ObservableFromIterable$FromIterableDisposable.run(ObservableFromIterable.java:98)
at io.reactivex.internal.operators.observable.ObservableFromIterable.subscribeActual(ObservableFromIterable.java:58)
at io.reactivex.Observable.subscribe(Observable.java:12090)
at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
at io.reactivex.Observable.subscribe(Observable.java:12090)
at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
at io.reactivex.Observable.subscribe(Observable.java:12090)
at io.reactivex.internal.operators.observable.ObservableToListSingle.subscribeActual(ObservableToListSingle.java:58)
at io.reactivex.Single.subscribe(Single.java:3438)
at io.reactivex.internal.operators.single.SingleDoOnSuccess.subscribeActual(SingleDoOnSuccess.java:35)
at io.reactivex.Single.subscribe(Single.java:3438)
at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
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:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
........................
It would be more Rx idiomatic if you rewrite your observable like that
compositeDisposable.add(Observable.fromArray(citiesList)
.flatMap(Observable::fromIterable)
.flatMapSingle(city ->
dataManager.getCityConditionsResponse(city.getQuery())
.map(response -> {
city.setTemp(response.getTemp());
city.setIcon(response.getIcon());
return city;
})
)
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
list -> view.showCitiesList(list),
error -> view.showServerErrorToast()
));
After that I think you problem will disappear.