尝试生成导航操作(由 safeargs gradle 插件生成)时遇到错误。源片段和目标片段都是bottomsheetdialogfragments,因此在相应的导航图中注册为对话框。
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/action_map_receipt_nav_graph"
app:startDestination="@id/paymentAccountsDialogFragment">
<dialog
android:id="@+id/paymentAccountsDialogFragment"
android:name="de.sevdesk.payments.ui.paymentAccounts.dialog.PaymentAccountsDialogFragment"
android:label="payment_accounts_dialog_fragment" >
<action
android:id="@+id/action_paymentAccountsDialogFragment_to_accountTransactionsDialogFragment"
app:destination="@id/accountTransactionsDialogFragment" />
</dialog>
<dialog
android:id="@+id/accountTransactionsDialogFragment"
android:name="de.sevdesk.payments.ui.accountTransactions.dialog.AccountTransactionsDialogFragment"
android:label="AccountTransactionsDialogFragment">
<argument
android:name="checkAccountId"
app:argType="string" />
<argument
android:name="checkAccountName"
app:argType="string" />
</dialog>
</navigation>
导航本身看起来像这样
val action = PaymentAccountsDialogFragmentDirections.actionPaymentAccountsDialogFragmentToAccountTransactionsDialogFragment(
it.checkAccountId,
it.checkAccountName
)
findNavController().navigate(action)
这会导致运行时异常:
2021-03-01 13:16:50.208 8888-8888/de.mypck.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.mypck.myapp, PID: 8888
java.lang.NoSuchMethodError: No virtual method actionPaymentAccountsDialogFragmentToAccountTransactionsDialogFragment(Ljava/lang/String;Ljava/lang/String;)Landroidx/navigation/NavDirections; in class Lde/mypck/payments/ui/paymentAccounts/dialog/PaymentAccountsDialogFragmentDirections$Companion; or its super classes (declaration of 'de.mypck.payments.ui.paymentAccounts.dialog.PaymentAccountsDialogFragmentDirections$Companion' appears in /data/app/~~UQv870BGZwE5Mh0gNeM8VQ==/de.mypck.myapp-JaRbZHxoM0f-CTNkO2Fsmw==/base.apk!classes4.dex)
at de.mypck.payments.ui.paymentAccounts.dialog.PaymentAccountsDialogFragment$setupViewModelObservers$1.onChanged(PaymentAccountsDialogFragment.kt:66)
at de.mypck.payments.ui.paymentAccounts.dialog.PaymentAccountsDialogFragment$setupViewModelObservers$1.onChanged(PaymentAccountsDialogFragment.kt:26)
at de.mypck.core.mvvm.SingleLiveEvent$observe$1.onChanged(SingleLiveEvent.kt:26)
at androidx.lifecycle.LiveData.considerNotify(LiveData.java:133)
at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:151)
at androidx.lifecycle.LiveData.setValue(LiveData.java:309)
at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
at de.mypck.core.mvvm.SingleLiveEvent.setValue(SingleLiveEvent.kt:35)
at de.mypck.payments.ui.paymentAccounts.PaymentAccountsViewModel.navTransactions(PaymentAccountsViewModel.kt:24)
at de.mypck.payments.ui.paymentAccounts.adapter.PaymentAccountItemAdapter$buildView$1.onClick(PaymentAccountItemAdapter.kt:88)
at android.view.View.performClick(View.java:8160)
at android.view.View.performClickInternal(View.java:8137)
at android.view.View.access$3700(View.java:888)
at android.view.View$PerformClick.run(View.java:30236)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)