导航组件对话框片段 NoSuchElementException
Navigation Component dialog fragment NoSuchElementException
-
android
-
android-fragments
-
android-navigation
-
android-architecture-navigation
-
bottomsheetdialogfragment
底部导航栏中有 3 个片段
-> 第三个片段有一个 viewpager2,其中有 2 个片段。
-> 单击 viewpager 的一个片段中的按钮会打开 BottomSheetDialogFragment,并在该 BottomSheetDialogFragment 中完成几个步骤后
-> 该片段被关闭并打开另一个 BottomSheetDialogFragment。
当最后一个 BottomSheetDialogFragment 关闭时,应用程序崩溃并出现以下错误
java.util.NoSuchElementException: Collection contains no element matching the predicate.
at androidx.navigation.fragment.DialogFragmentNavigator$observer.onStateChanged(DialogFragmentNavigator.kt:216)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:284)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:302)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148)
at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
at androidx.fragment.app.Fragment.performStop(Fragment.java:3179)
at androidx.fragment.app.FragmentStateManager.stop(FragmentStateManager.java:619)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:297)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1793)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1711)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1654)
at androidx.fragment.app.FragmentManager.run(FragmentManager.java:488)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7660)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
我一个月前升级到导航库 2.4.0-alpha03 并忽略了这个问题,认为它在 alpha 中并且会被修复,alpha05 已经出来并且仍然相同,我决定转到稳定版本 2.3 .5 并且错误仍然存在。
这是 gradle(模块)
apply plugin: "androidx.navigation.safeargs.kotlin"
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0-alpha05'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.0-alpha05'
gradle(模块)
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha05"
导航图如下所示
<fragment
android:id="@+id/profile"
android:name="com.example.user.profile.ProfileFragment"
android:label="Profile"
tools:layout="@layout/fragment_profile">
<action
android:id="@+id/action_profile_to_editProfileFragment"
app:destination="@id/editProfileFragment"
app:enterAnim="@anim/from_right"
app:exitAnim="@anim/to_left"
app:popEnterAnim="@anim/from_left"
app:popExitAnim="@anim/to_right" />
<action
android:id="@+id/action_profile_to_predefinedHabitsFragment"
app:destination="@id/predefinedHabitsFragment" />
<action
android:id="@+id/action_profile_to_editHabitBottomSheetFragment"
app:destination="@id/editHabitBottomSheetFragment" />
</fragment>
<dialog
android:id="@+id/addPredefinedHabitBottomSheet"
android:name="com.example.habits.add.predefined.AddPredefinedHabitBottomSheet"
android:label="AddPredefinedHabitBottomSheet"
tools:layout="@layout/add_predefined_habit_bottom_sheet">
<argument
android:name="habitData"
app:argType="com.example.predefined.models.PredefinedHabitsModelItem" />
</dialog>
<dialog
android:id="@+id/addCustomHabitBottomSheet"
android:name="com.iku.habits.add.custom.AddCustomHabitBottomSheet"
android:label="AddCustomHabitBottomSheet"
tools:layout="@layout/add_custom_habit_bottom_sheet" />
Google 问题中描述的解决方案 - https://issuetracker.google.com/issues/191073055#comment14
android
android-fragments
android-navigation
android-architecture-navigation
bottomsheetdialogfragment
底部导航栏中有 3 个片段
-> 第三个片段有一个 viewpager2,其中有 2 个片段。
-> 单击 viewpager 的一个片段中的按钮会打开 BottomSheetDialogFragment,并在该 BottomSheetDialogFragment 中完成几个步骤后
-> 该片段被关闭并打开另一个 BottomSheetDialogFragment。
当最后一个 BottomSheetDialogFragment 关闭时,应用程序崩溃并出现以下错误
java.util.NoSuchElementException: Collection contains no element matching the predicate.
at androidx.navigation.fragment.DialogFragmentNavigator$observer.onStateChanged(DialogFragmentNavigator.kt:216)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:284)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:302)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148)
at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
at androidx.fragment.app.Fragment.performStop(Fragment.java:3179)
at androidx.fragment.app.FragmentStateManager.stop(FragmentStateManager.java:619)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:297)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1793)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1711)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1654)
at androidx.fragment.app.FragmentManager.run(FragmentManager.java:488)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7660)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
我一个月前升级到导航库 2.4.0-alpha03 并忽略了这个问题,认为它在 alpha 中并且会被修复,alpha05 已经出来并且仍然相同,我决定转到稳定版本 2.3 .5 并且错误仍然存在。
这是 gradle(模块)
apply plugin: "androidx.navigation.safeargs.kotlin"
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0-alpha05'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.0-alpha05'
gradle(模块)
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha05"
导航图如下所示
<fragment
android:id="@+id/profile"
android:name="com.example.user.profile.ProfileFragment"
android:label="Profile"
tools:layout="@layout/fragment_profile">
<action
android:id="@+id/action_profile_to_editProfileFragment"
app:destination="@id/editProfileFragment"
app:enterAnim="@anim/from_right"
app:exitAnim="@anim/to_left"
app:popEnterAnim="@anim/from_left"
app:popExitAnim="@anim/to_right" />
<action
android:id="@+id/action_profile_to_predefinedHabitsFragment"
app:destination="@id/predefinedHabitsFragment" />
<action
android:id="@+id/action_profile_to_editHabitBottomSheetFragment"
app:destination="@id/editHabitBottomSheetFragment" />
</fragment>
<dialog
android:id="@+id/addPredefinedHabitBottomSheet"
android:name="com.example.habits.add.predefined.AddPredefinedHabitBottomSheet"
android:label="AddPredefinedHabitBottomSheet"
tools:layout="@layout/add_predefined_habit_bottom_sheet">
<argument
android:name="habitData"
app:argType="com.example.predefined.models.PredefinedHabitsModelItem" />
</dialog>
<dialog
android:id="@+id/addCustomHabitBottomSheet"
android:name="com.iku.habits.add.custom.AddCustomHabitBottomSheet"
android:label="AddCustomHabitBottomSheet"
tools:layout="@layout/add_custom_habit_bottom_sheet" />
Google 问题中描述的解决方案 - https://issuetracker.google.com/issues/191073055#comment14