android - 缺少带有 ID 的必需视图,导航图 android
问题描述
我的应用程序中有 2 个导航图我有 2 个名称相同但 UI 不同的片段,并且也位于不同的包中。
现在我导航到它工作的一个片段,当我导航到另一个片段时,我得到了异常
java.lang.NullPointerException: Missing required view with ID: com.octave.staging:id/cashPieChart
at com.octave.more.databinding.CashDistributionFragmentBinding.bind(CashDistributionFragmentBinding.java:104)
at com.octave.more.databinding.CashDistributionFragmentBinding.inflate(CashDistributionFragmentBinding.java:65)
at com.octave.more.cash.CashDistributionFragment.onCreateView(CashDistributionFragment.kt:34)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
这些是我的导航图
<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/dashboard_nav_graph"
app:startDestination="@id/dashboardFragment">
<fragment
android:id="@+id/dashboardFragment"
android:name="com.octave.dashboard.DashboardFragment"
android:label="dashboard_fragment"
tools:layout="@layout/dashboard_fragment" >
<action
android:id="@+id/action_dashboardFragment_to_equityFragment"
app:destination="@id/dashboardCashDistributionFragment" />
<action
android:id="@+id/action_dashboardFragment_to_cashDistributionFragment"
app:destination="@id/dashboardEquityFragment" />
</fragment>
<fragment
android:id="@+id/dashboardEquityFragment"
android:name="com.octave.dashboard.equity.EquityFragment"
tools:layout="@layout/equity_fragment"
android:label="EquityFragment" />
<fragment
android:id="@+id/dashboardCashDistributionFragment"
android:name="com.octave.dashboard.cash.CashDistributionFragment"
android:label="cash_distribution_fragment"
tools:layout="@layout/cash_distribution_fragment" />
</navigation>
第二张图
<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/more_nav_graph"
app:startDestination="@id/moreFragment">
<fragment
android:id="@+id/moreFragment"
android:name="com.octave.more.MoreFragment"
android:label="more_fragment"
tools:layout="@layout/more_fragment">
<action
android:id="@+id/action_moreFragment_to_equityFragment"
app:destination="@id/equityFragment" />
<action
android:id="@+id/action_moreFragment_to_cashDistributionFragment"
app:destination="@id/cashDistributionFragment" />
</fragment>
<fragment
android:id="@+id/equityFragment"
android:name="com.octave.more.equity.EquityFragment"
android:label="equity_fragment"
tools:layout="@layout/equity_fragment" />
<fragment
android:id="@+id/cashDistributionFragment"
android:name="com.octave.more.cash.CashDistributionFragment"
android:label="cash_distribution_fragment"
tools:layout="@layout/cash_distribution_fragment" />
</navigation>
导航代码如下
findNavController().navigate(DashboardFragmentDirections.actionDashboardFragmentToEquityFragment())
findNavController().navigate(MoreFragmentDirections.actionMoreFragmentToCashDistributionFragment())
两者都具有不同的操作 ID 以及位置。似乎无法弄清楚问题
解决方案
我的项目采用多模块方法问题是由于视图绑定,因为布局 xml 也具有相同的名称并位于 2 个不同的模块中。
更改 1 xml 的名称后,它正在工作。
但是我没有得到相同的文件名存在于不同的包中,但视图绑定将其引用到第一个。
推荐阅读
- python - 为什么if语句会影响私有属性的存在?
- angular - 如何使用角度的材质虚拟滚动以编程方式滚动到项目?
- java - 有没有办法在Spring-Boot java应用程序中使用host-IP作为主机通过不同的机器远程连接到redis服务器
- python - 比较不同长度的多个 pandas 列以访问最后一列
- python - 在 YouTube 上搜索并返回 Python 中的所有链接
- python - 在数据框的一部分和选定行之间按行划分
- ionic-framework - 如何限制用户从 Ionic 的项目列表中仅选择一项
- date - SSRS 2008 - 为什么某些月份没有返回矩阵中的结果,但结果显示在 SQL 查询窗格中?
- python - 错误系统调用产生 C:\Windows\system32\cmd.exe
- ios - 如何在uitextfield编辑的边框线上添加占位符文本