Issue
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.
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. Can't seem to figure out the issue
Solution
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.
After changing the name of 1 xml it is working.
However what I don't get is same file names exists in different packages and yet view binding referenced it to first one.
Answered By - WISHY
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.