gpt4 book ai didi

android - IllegalArgumentException : Navigation action/destination cannot be found from the current destination Destination [Navigation Error]

转载 作者:行者123 更新时间:2023-12-04 23:44:16 28 4
gpt4 key购买 nike

我一般是导航图和导航组件的新手,我正在尝试将数据从位于“PrivSectionFragment”中的回收器 View 传递到“PrivSectionDetailFragment”。不幸的是,每当我运行该应用程序时,我都会在日志中收到此错误

 java.lang.IllegalArgumentException: Navigation action/destination com.gazelle.wadifatk:id/action_privSectionFragment_to_privsDetailFragment cannot be found from the current destination Destination(com.gazelle.wadifatk:id/jobsFragment) label=الوظائف class=com.gazelle.wadifatk.jobLists.jobsFragment
at androidx.navigation.NavController.navigate(NavController.java:940)
at androidx.navigation.NavController.navigate(NavController.java:877)
at androidx.navigation.NavController.navigate(NavController.java:863)
at androidx.navigation.NavController.navigate(NavController.java:1159)
at com.gazelle.wadifatk.jobLists.PrivListAdapter.onBindViewHolder$lambda-0(PrivListAdapter.kt:55)
这是它所指的地方//它指的是我的回收器适配器
PushDownAnim.setPushDownAnimTo(holder.card_view)
//.setScale(PushDownAnim.MODE_SCALE, 0.89f)
.setOnClickListener {
val sendData = PrivSectionFragmentDirections
.actionPrivSectionFragmentToPrivsDetailFragment(priv_list[position])
Navigation.findNavController(view).navigate(sendData)
}
这是 my_nav.xml //蓝色圆圈
my_nav photo
请记住,我能够将数据从“LatestNewsFragment”传递到“NewsDetailsFragment”
只是通过使用相同的 Action ,我不知道为什么它接受了这些 fragment 之间传递的数据,并且不接受从“PrivSectionFragment”到“PrivSectionDetailFragment”的数据。
这是 fragment 的代码
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_nav"
app:startDestination="@id/latestNewsFragment">

<fragment
android:id="@+id/latestNewsFragment"
android:name="com.gazelle.wadifatk.newsList.LatestNewsFragment"
android:label="اخر الاخبار"
tools:layout="@layout/fragment_latest_news" >
<action
android:id="@+id/action_latestNewsFragment_to_jobsFragment"
app:destination="@id/jobsFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim" />
<action
android:id="@+id/action_latestNewsFragment_to_newsDetailFragment"
app:destination="@id/newsDetailFragment"
app:enterAnim="@android:anim/slide_in_left"
app:exitAnim="@android:anim/slide_out_right"
app:popEnterAnim="@android:anim/slide_in_left"
app:popExitAnim="@android:anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/jobsFragment"
android:name="com.gazelle.wadifatk.jobLists.jobsFragment"
android:label="الوظائف"
tools:layout="@layout/fragment_jobs" >
<action
android:id="@+id/action_jobsFragment_to_govSectionFragment"
app:destination="@id/govSectionFragment" />
<action
android:id="@+id/action_jobsFragment_to_privSectionFragment2"
app:destination="@id/privSectionFragment" />
<action
android:id="@+id/action_jobsFragment_to_latestNewsFragment"
app:destination="@id/latestNewsFragment" />
</fragment>
<fragment
android:id="@+id/privSectionFragment"
android:name="com.gazelle.wadifatk.jobLists.PrivSectionFragment"
android:label="PrivSectionFragment" >
<action
android:id="@+id/action_privSectionFragment_to_privsDetailFragment"
app:destination="@id/privsDetailFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim" />
<action
android:id="@+id/action_privSectionFragment_to_jobsFragment"
app:destination="@id/jobsFragment" />
</fragment>
<fragment
android:id="@+id/newsDetailFragment"
android:name="com.gazelle.wadifatk.newsList.NewsDetailFragment"
android:label="التفاصيل"
tools:layout="@layout/fragment_news_detail">
<action
android:id="@+id/action_newsDetailFragment_to_latestNewsFragment"
app:destination="@id/latestNewsFragment"
app:enterAnim="@android:anim/slide_in_left"
app:exitAnim="@android:anim/slide_out_right"
app:popEnterAnim="@android:anim/slide_in_left"
app:popExitAnim="@android:anim/slide_out_right" />
<argument
android:name="news_data_list"
app:argType="com.gazelle.wadifatk.newsList.NewsListViewModel" />

</fragment>

<fragment
android:id="@+id/privsDetailFragment"
android:name="com.gazelle.wadifatk.jobLists.PrivsDetailFragment"
android:label="التفاصيل"
tools:layout="@layout/fragment_privs_detail" >

<argument
android:name="priv_data_list"
app:argType="com.gazelle.wadifatk.jobLists.PrivListViewModel" />
<action
android:id="@+id/action_privsDetailFragment_to_privSectionFragment"
app:destination="@id/privSectionFragment" />

</fragment>

这是jobsFragment()的屏幕截图
enter image description here

最佳答案

您只需添加 JobsFragment在您的导航图中并在此 fragment 中为 PrivsDetailFragment 添加操作.

<fragment
android:id="@+id/jobsFragment"
android:name="com.gazelle.wadifatk.jobLists.jobsFragment"
android:label="الوظائف"
tools:layout="@layout/fragment_jobs" >
<action
android:id="@+id/action_jobsFragment_to_govSectionFragment"
app:destination="@id/govSectionFragment" />
<action
android:id="@+id/action_jobsFragment_to_latestNewsFragment"
app:destination="@id/latestNewsFragment" />
<action
android:id="@+id/action_jobsFragment_to_privsDetailFragment"
app:destination="@id/privsDetailFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim" />
</fragment>
然后在你的适配器中,使用这个 Action :
PushDownAnim.setPushDownAnimTo(holder.card_view)
//.setScale(PushDownAnim.MODE_SCALE, 0.89f)
.setOnClickListener {
val sendData = JobFragmentDirections.actionJobFragmentToPrivsDetailFragment(priv_list[position])
Navigation.findNavController(view).navigate(sendData)
}
您可以删除 privSectionFragment从导航图。

关于android - IllegalArgumentException : Navigation action/destination cannot be found from the current destination Destination [Navigation Error],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69861301/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com