Code snippet from my fragment where my app crashes:
class SplashChooseFragment : Fragment(R.layout.fr_splash_choose) {
private val mBind by viewBinding(FrSplashChooseBinding::bind)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
mBind.btnLogin.setOnClickListener {
findNavController().navigate(R.id.action_fr_splash_choose_to_nav_login)
}
mBind.btnRegister.setOnClickListener {
findNavController().navigate(R.id.action_fr_splash_choose_to_nav_register)
}
}
}
Full stack trace of the exception:
java.lang.AbstractMethodError: abstract method "void androidx.lifecycle.DefaultLifecycleObserver.onCreate(androidx.lifecycle.LifecycleOwner)"
at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:36)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:265)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:307)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148)
at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
at androidx.fragment.app.FragmentViewLifecycleOwner.handleLifecycleEvent(FragmentViewLifecycleOwner.java:88)
at androidx.fragment.app.Fragment.restoreViewState(Fragment.java:653)
at androidx.fragment.app.Fragment.restoreViewState(Fragment.java:3010)
at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:3001)
at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:580)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:285)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2106)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:914)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7564)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
But when I create fragment's view like this, everything works just fine, no crashes:
class SplashChooseFragment : Fragment() {
//private val mBind by viewBinding(FrSplashChooseBinding::bind)
private var _binding: FrSplashChooseBinding? = null
val mBind: FrSplashChooseBinding
get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FrSplashChooseBinding.inflate(inflater, container, false)
return mBind.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
mBind.btnLogin.onClick {
findNavController().navigate(R.id.action_fr_splash_choose_to_nav_login)
}
mBind.btnRegister.onClick {
findNavController().navigate(R.id.action_fr_splash_choose_to_nav_register)
}
}
}
Code snippet from my fragment where my app crashes:
Full stack trace of the exception:
But when I create fragment's view like this, everything works just fine, no crashes:
I use 1.4.7 version of the library