简体   繁体   English

缺少带 ID 的必需视图、导航图 android

[英]Missing required view with ID, navigation graph android

I have 2 navigation graphs in my app I have 2 fragments with same name but different UI and resides in different package as well.我的应用程序中有 2 个导航图我有 2 个具有相同名称但不同 UI 的片段,并且也驻留在不同的包中。

Now I navigate to one fragment it works and while I navigate to other I get the exception现在我导航到一个它工作的片段,当我导航到另一个片段时,我得到了异常

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)

These are my nav graphs这些是我的导航图

<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>

the second graph第二张图

<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>

And the the navigation code is as导航代码如下

findNavController().navigate(DashboardFragmentDirections.actionDashboardFragmentToEquityFragment())

findNavController().navigate(MoreFragmentDirections.actionMoreFragmentToCashDistributionFragment())

Both have different action id's as well as location as well.两者都有不同的动作 ID 以及位置。 Can't seem to figure out the issue似乎无法弄清楚问题

My project is on multi module approach Issue was due to view binding as both the layout xml's also had the same name and resides in 2 different module.我的项目采用多模块方法问题是由于视图绑定,因为布局 xml 也具有相同的名称并驻留在 2 个不同的模块中。

After changing the name of 1 xml it is working.更改 1 xml 的名称后,它正在工作。

However what I don't get is same file names exists in different packages and yet view binding referenced it to first one.然而,我没有得到相同的文件名存在于不同的包中,但视图绑定将它引用到第一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM