簡體   English   中英

缺少帶 ID 的必需視圖、導航圖 android

[英]Missing required view with ID, navigation graph 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 的名稱后,它正在工作。

然而,我沒有得到相同的文件名存在於不同的包中,但視圖綁定將它引用到第一個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM