runtime-errorfragmentinflate-exception

android.view.InflateException: Binary XML file line #15: Binary XML file line #19: Error inflating class fragment


I have Error while launching app. My code has no error still I am getting this Error. Help me how to fix it.

android.view.InflateException: Binary XML file line #15: Binary XML file line #19: Error inflating class fragment

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/app_bar_main1">

    <fragment
        android:id="@+id/nav_host_fragment_content_main1"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"                        <---- THIS IS 15
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />   <----THIS IS 19

</androidx.constraintlayout.widget.ConstraintLayout>

Solution

  • I finally found the real problem. I had a problem with viewmodel. This error occurred because there was a logical error in the fragment.