smarteist / Android-Image-Slider

Android Auto Image Slider
Apache License 2.0
947 stars 299 forks source link

Observer is already registered issue #143

Open faizandarwesh opened 4 years ago

faizandarwesh commented 4 years ago

When coming back from fragment app get crash with java.lang.IllegalStateException:Observercom.smarteist.autoimageslider.SliderPager$PagerObserver@cd8f677 is already registered.

java.lang.IllegalStateException: Observer com.smarteist.autoimageslider.SliderPager$PagerObserver@cd8f677 is already registered.
        at android.database.Observable.registerObserver(Observable.java:49)
        at androidx.viewpager.widget.PagerAdapter.registerDataSetObserver(PagerAdapter.java:303)
        at com.smarteist.autoimageslider.InfiniteAdapter.InfinitePagerAdapter.registerDataSetObserver(InfinitePagerAdapter.java:140)
        at com.smarteist.autoimageslider.SliderPager.setAdapter(SliderPager.java:478)
        at com.smarteist.autoimageslider.SliderView.setSliderAdapter(SliderView.java:194)
        at com.example.tasteofblue.ui.fragments.hotels.HotelDescriptionFragment$setObservers$1.onChanged(HotelDescriptionFragment.kt:133)
        at com.example.tasteofblue.ui.fragments.hotels.HotelDescriptionFragment$setObservers$1.onChanged(HotelDescriptionFragment.kt:36)
        at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
        at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:149)
        at androidx.lifecycle.LiveData.setValue(LiveData.java:307)
        at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
        at com.example.tasteofblue.ui.fragments.hotels.viewmodel.HotelDescriptionViewModel$fetchHotelPhotos$1.invokeSuspend(HotelDescriptionViewModel.kt:37)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
2020-06-11 18:10:47.343 12334-12334/com.example.tasteofblue D/AndroidRuntime: Shutting down VM
2020-06-11 18:10:47.351 12334-12334/com.example.tasteofblue E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.tasteofblue, PID: 12334
    java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 0, found: 680400 Pager id: com.example.tasteofblue:id/vp_slider_layout Pager class: class com.smarteist.autoimageslider.SliderPager Problematic adapter: class com.smarteist.autoimageslider.InfiniteAdapter.InfinitePagerAdapter

Any help will be highly appreciated. Looking forward a quick response.

HafijurRahmanEjaro commented 2 years ago

Facing the same issue, have you found the solution? java.lang.IllegalStateException: Observer com.smarteist.autoimageslider.IndicatorView.PageIndicatorView$1@a4c454b was not registered.