When a user the second time navigates to a fragment with a ViewPager, an exception is thrown:
Java.Lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00064] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:195
at Android.Support.V4.App.FragmentManagerInvoker.GetFragment (Android.OS.Bundle bundle, System.String key) [0x00064] in :0
at MvvmCross.Droid.Support.V4.MvxFragmentPagerAdapter2.RestoreState (IParcelable state, Java.Lang.ClassLoader loader) [0x000bd] in :0
at Android.Support.V4.View.PagerAdapter.n_RestoreState_Landroid_os_Parcelable_Ljava_langClassLoader (IntPtr jnienv, IntPtr native__this, IntPtr native_state, IntPtr native_loader) [0x00019] in :0
at at (wrapper dynamic-method) System.Object:60a811d7-76a2-41aa-a8a0-ff5c5f50127d (intptr,intptr,intptr,intptr)
at --- End of managed exception stack trace ---
at java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
at at android.support.v4.app.FragmentManagerImpl.getFragment(FragmentManager.java:667)
at at md559873f5c332c022bf8710d3c9fbb7bb2.MvxFragmentPagerAdapter2.n_restoreState(Native Method)
at at md559873f5c332c022bf8710d3c9fbb7bb2.MvxFragmentPagerAdapter2.restoreState(MvxFragmentPagerAdapter2.java:74)
at at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1319)
at at android.view.View.dispatchRestoreInstanceState(View.java:13740)
at at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2887)
at at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2893)
at at android.view.View.restoreHierarchyState(View.java:13718)
at at android.support.v4.app.Fragment.restoreViewState(Fragment.java:468)
at at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1094)
at at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
at at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
at at android.view.View.performClick(View.java:4780)
at at android.view.View$PerformClick.run(View.java:19866)
at at android.os.Handler.handleCallback(Handler.java:739)
at at android.os.Handler.dispatchMessage(Handler.java:95)
at at android.os.Looper.loop(Looper.java:135)
at at android.app.ActivityThread.main(ActivityThread.java:5254)
at at java.lang.reflect.Method.invoke(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:372)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
When a user the second time navigates to a fragment with a ViewPager, an exception is thrown:
Sample project can be found here: https://github.com/vecalion/MvvmCross-Samples/tree/viewpager_crash
Steps to reproduce
The exception is thrown by this call: https://github.com/MvvmCross/MvvmCross-AndroidSupport/blob/master/MvvmCross.Droid.Support.V4/MvxFragmentPagerAdapter2.cs#L158
Suppressing the exception with try catch might be used as work-around, but what causes the issue?