title: NavigationUI.setupWithNavController get java.lang.NullPointerException
body: <p>I am trying to implement navigation between fragments using bottom navbar but when using NavigationUI.setupWithNavController when i click on any tab i get error java.lang.NullPointerException at androidx.navigation.ui.NavigationUI.onNavDestinationSelected please help i dont understand what not this way.</p>
  <p>Exception</p>
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.testfragments, PID: 12083
  java.lang.NullPointerException
      at androidx.navigation.ui.NavigationUI.onNavDestinationSelected(NavigationUI.kt:69)
      at androidx.navigation.ui.NavigationUI.setupWithNavController$lambda-6(NavigationUI.kt:602)
      at androidx.navigation.ui.NavigationUI.$r8$lambda$6wzEv9QqEZKdQFS1sQQy-bdQvgE(Unknown Source:0)
      at androidx.navigation.ui.NavigationUI$$ExternalSyntheticLambda2.onNavigationItemSelected(Unknown Source:2)
      at com.google.android.material.navigation.NavigationBarView$1.onMenuItemSelected(NavigationBarView.java:295)
      at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
      at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
      at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
      at com.google.android.material.navigation.NavigationBarMenuView$1.onClick(NavigationBarMenuView.java:133)
      at android.view.View.performClick(View.java:6256)
      at android.view.View$PerformClick.run(View.java:24701)
      at android.os.Handler.handleCallback(Handler.java:789)
      at android.os.Handler.dispatchMessage(Handler.java:98)
      at android.os.Looper.loop(Looper.java:164)
      at android.app.ActivityThread.main(ActivityThread.java:6541)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  </code></pre>
  <p>MainActivity.java</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  private NavController navController;
  private AppBarConfiguration appBarConfiguration;
  
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment_container);
      NavController navController = navHostFragment.getNavController();
      BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_menu);
      appBarConfiguration = new AppBarConfiguration.Builder(R.id.user, R.id.orders, R.id.products, R.id.companies, R.id.map).build();
      NavigationUI.setupWithNavController(bottomNavigationView, navController);
  }
  
  @Override
  public boolean onSupportNavigateUp() {
      return navController.navigateUp();
  }
  }
  </code></pre>
  <p>activity_main.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout 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;
  android:orientation=&quot;vertical&quot;
  tools:context=&quot;.MainActivity&quot;&gt;
  
  &lt;androidx.fragment.app.FragmentContainerView
      android:id=&quot;@+id/nav_host_fragment_container&quot;
      android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;0dp&quot;
      android:layout_weight=&quot;1&quot;
      app:defaultNavHost=&quot;true&quot;/&gt;
  
  &lt;com.google.android.material.bottomnavigation.BottomNavigationView
      android:id=&quot;@+id/bottom_navigation_menu&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      app:menu=&quot;@menu/bottom_navigation_menu&quot; /&gt;
  </code></pre>
  
  <p>bottom_navigation_menu.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
  &lt;item
      android:id=&quot;@+id/user&quot;
      android:icon=&quot;@drawable/ic_user_black_24dp&quot;
      android:title=&quot;@string/title_user&quot;/&gt;
  &lt;item
      android:id=&quot;@+id/orders&quot;
      android:icon=&quot;@drawable/ic_orders_black_24dp&quot;
      android:title=&quot;@string/title_orders&quot;/&gt;
  &lt;item
      android:id=&quot;@+id/products&quot;
      android:icon=&quot;@drawable/ic_products_black_24dp&quot;
      android:title=&quot;@string/title_products&quot;/&gt;
  &lt;item
      android:id=&quot;@+id/companies&quot;
      android:icon=&quot;@drawable/ic_companies_black_24dp&quot;
      android:title=&quot;@string/title_companies&quot;/&gt;
  &lt;item
      android:id=&quot;@+id/map&quot;
      android:icon=&quot;@drawable/ic_map_black_24dp&quot;
      android:title=&quot;@string/title_map&quot;/&gt;
  
  &lt;/menu&gt;
  </code></pre>
  <p>nav_graph.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;navigation
  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  android:id=&quot;@+id/nav_graph&quot;
  app:startDestination=&quot;@+id/user&quot;&gt;
  
  &lt;include app:graph=&quot;@navigation/user&quot;/&gt;
  &lt;include app:graph=&quot;@navigation/orders&quot;/&gt;
  &lt;include app:graph=&quot;@navigation/products&quot;/&gt;
  &lt;include app:graph=&quot;@navigation/companies&quot;/&gt;
  &lt;include app:graph=&quot;@navigation/map&quot;/&gt;
  
  &lt;/navigation&gt;
  </code></pre>