android-viewbinding
android-viewbinding copied to clipboard
Fatal Exception: java.lang.IllegalStateException
Hi, on some devices when open BottomSheetDialogFragment app got crashed with this exception:
Fatal Exception: java.lang.IllegalStateException Can't access the Fragment View's LifecycleOwner when getView() is null i.e., before onCreateView() or after onDestroyView()
Exception is pointing to viewbindig method: DoWorkoutFragment.getFragmentBinding (DoWorkoutFragment.kt:50) DoWorkoutFragment.access$getFragmentBinding (DoWorkoutFragment.kt:38) DoWorkoutFragment$setupDoWorkoutScreen$1.invokeSuspend (DoWorkoutFragment.kt:79) kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33) kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106)
Which is inside of view binding delegate. What do I need to do to avoid this?
Can you provide how do you import the by viewBinding()
is @glebkravchenko?
What do you mean? Import to the project? Or import inside of the fragment?
@glebkravchenko, it seems that @yogacp presumed that this is the usual incorrect import from dialog viewbinding to fragment viewbinding. however, this bug happened to us too, and there is nothing wrong with the import
It also happened to me with the same error message but it was on Fragment instead of BottomSheetDialogFragment, and I check i imported the correct viewbinding.
I think it caused by this line
@yogacp you might want to see this
https://medium.com/@Zhuinden/an-update-to-the-fragmentviewbindingdelegate-the-bug-weve-inherited-from-autoclearedvalue-7fc0a89fcae1
We need a fix for that because it's crashing the app every time when I'm going by saved fragments stack back ...
@glebkravchenko @thegarlynch Make sure not to access the view before onCreateView and after onDestroyView.
If you use Flow, you can read this article
I experienced the same thing after I read my code, it turns out that there is something that does set view before onCreateView and after onDestroyView.