title: Bottom Navigation bar with Navigation Component didn't change the Fragment?
body: <p><code>mainactivity.xml</code></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.main.MainActivity&quot;&gt;
  
  
  
  
      &lt;fragment
          android:id=&quot;@+id/bottom_nav_control&quot;
          android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
          android:layout_width=&quot;409dp&quot;
          android:layout_height=&quot;673dp&quot;
          app:defaultNavHost=&quot;true&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/bottomNavigationView&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:navGraph=&quot;@navigation/my_nav_home&quot; /&gt;
      &lt;com.google.android.material.bottomnavigation.BottomNavigationView
          android:id=&quot;@+id/bottomNavigationView&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:menu=&quot;@menu/bottom_nav&quot;
  
          &gt;
      &lt;/com.google.android.material.bottomnavigation.BottomNavigationView&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p><code>MainActivity.kt</code></p>
  <pre><code>class MainActivity : AppCompatActivity() {
      private lateinit var binding: MainactivityBinding
  
      private lateinit var navController: NavController
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          binding = MainactivityBinding.inflate(layoutInflater)
          setContentView(binding.root)
  
          navController = Navigation.findNavController(this, R.id.bottom_nav_control)
          setup WithNavController(binding.bottomNavigationView, navController)
      }
  
  }
  </code></pre>
  <p><code>Fragment-1</code></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.navigation.fragment1&quot;&gt;
  
  
      &lt;TextView
          android:id=&quot;@+id/fragment1&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;Music Player&quot;
          android:textSize=&quot;26dp&quot;
  
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>there actually made 3 fragments for bottom navigation bar but i given one fragment code above and add them in my navigation bar with navigation component and mainactivity when i try run it does not change the fragment on bottom bar stuck on home fragment and it didn't change.</p>
  <blockquote>
  <p>i tried other way of code on my mainactivity.kt but ii didn't work when i run it automatically close the app
  Give me a solution that could actually work</p>
  </blockquote>