Crash when navigating between fragments using app:navgraph in Android

65 Views Asked by At

My app is crashing randomly with the following error response. It shows a crash on this XML code at line number

app:navGraph="@navigation/nav_radio" this.

 <fragment
    android:id="@+id/frame_radio"
    android:name="androidx.navigation.fragment.NavHostFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintTop_toBottomOf="@+id/rvHeadrs"
    app:layout_constraintBottom_toBottomOf="parent"
    android:layout_marginTop="10dp"
    android:background="@color/dark_blue"
    android:layout_marginBottom="45dp"
    app:navGraph="@navigation/nav_radio"
/>

Fatal Exception: java.lang.RuntimeException ComponentInfo{tunnel.dimf/tunnel.dimf.radio.RadioFragmentActivity}: android.view.InflateException: Binary XML file line #47: Binary XML file line #47: Error inflating class fragment

I have changed a below lines:-

  1. Changes

"android:name="androidx.navigation.fragment.NavHostFragment" line into " class="androidx.navigation.fragment.NavHostFragment".

  1. Add ktx dependencies:-

implementation "androidx.navigation:navigation-fragment-ktx:2.3.0-alpha04" implementation "androidx.navigation:navigation-ui-ktx:2.3.0-alpha04"

  1. Add this line in activity `oncreate1 method.

NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.frame_radio); NavController navController = navHostFragment.getNavController();

4.Add in manifest android:largeHeap="true".

0

There are 0 best solutions below