title: How to use navigation component in fragment Android
body: <p>I want to use Navigation component in my fragment.</p>
  <p>My XML code like this</p>
  <pre><code> &lt;androidx.constraintlayout.widget.ConstraintLayout
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;&gt;
  
      ...
  
      &lt;androidx.fragment.app.FragmentContainerView
          android:id=&quot;@+id/fragment_nav_host_home&quot;
          android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;0dp&quot;
          app:defaultNavHost=&quot;true&quot;
          app:navGraph=&quot;@navigation/home_navigation&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/app_bar&quot; /&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>And Initializing navigation code like this.</p>
  <pre><code>class HomeFragment : Fragment() {
  
     //...initialie view
  
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
  
          val navController = Navigation.findNavController(binding.fragmentNavHostHome)
          navController.setGraph(R.navigation.home_navigation)
  
          val appBarConfiguration = AppBarConfiguration(navController.graph)
  
          NavigationUI.setupActionBarWithNavController(requireActivity() as AppCompatActivity, navController, appBarConfiguration)
  
      
      }
  
  }
  </code></pre>
  <p>And after I launched my app, I got an error message like this.</p>
  <pre><code>View androidx.fragment.app.FragmentContainerView{... app:id/fragment_nav_host_home} does not have a NavController set
  </code></pre>
  <p>Also, findNavController() does not work.</p>
  <p>How can I use navigation component in my fragment</p>