androidbroadcast / ViewBindingPropertyDelegate

Make work with Android View Binding simpler
https://proandroiddev.com/make-android-view-binding-great-with-kotlin-b71dd9c87719
Apache License 2.0
1.42k stars 102 forks source link

Fatal Exception: java.lang.IllegalStateException: Host view isn't ready. LifecycleViewBindingProperty.isViewInitialized return false #122

Closed sukhov-13 closed 7 months ago

sukhov-13 commented 7 months ago

Fatal Exception: java.lang.IllegalStateException: Host view isn't ready. LifecycleViewBindingProperty.isViewInitialized return false at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:87) at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:71) at com.hakbah.ui.navigation.marketplace.wishlist.WishlistBottomSheet.getBinding(WishlistBottomSheet.kt:40) at com.hakbah.ui.navigation.marketplace.wishlist.WishlistBottomSheet.onNoWishListResult(WishlistBottomSheet.kt:235) at com.hakbah.ui.navigation.home.HomeFragmentPresenter.getWishList(HomeFragmentPresenter.java:356) at com.hakbah.ui.navigation.home.HomeFragmentModel.onNext(HomeFragmentModel.java:114) at com.hakbah.ui.navigation.home.HomeFragmentModel.onNext(HomeFragmentModel.java:17) at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:201) at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:255) at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:124) at android.os.Handler.handleCallback(Handler.java:900) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8676) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

kirich1409 commented 7 months ago

Hi. It's look like you try update UI before Fragment's View created or it after it was destroyed. Before access to View from callback or async operation check is view ready

class HomeFragment : Fragment() {
    fun onNoWishListResult(...) {
       // Check that Fragment view isn't null
       if (view != null) {
           // access viewbinding and update view
       }
    }
}