androidandroid-lifecycleandroidx

Attempt to invoke virtual method 'void androidx.lifecycle.ViewModel.clear()' on a null object reference


So in last couple versions of my application Firebase Crashlytics is reporting crashes in ViewModelStore class from androidX lifecycle library. The version of lifecycle library that I use is 2.0.0. I couldn't find any reported issues on Google issue tracker related for this one. Here is the log:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.lifecycle.ViewModel.clear()' on a null object reference
   at androidx.lifecycle.ViewModelStore.clear(ViewModelStore.java:62)
   at androidx.fragment.app.FragmentManagerViewModel.clearNonConfigState(FragmentManagerViewModel.java:169)
   at androidx.fragment.app.FragmentStateManager.destroy(FragmentStateManager.java:480)
   at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1294)
   at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1354)
   at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1432)
   at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:442)
   at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2167)
   at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1990)
   at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1945)
   at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1847)
   at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
   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:6938)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Does someone has a clue what could be an issue?


Solution

  • It seems this issue is fixed with the latest updates in the Fragment, Lifecycle, and ViewModel AndroidX libraries.

    It was verified with androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0