title: Using Navigation Architecture Component with Navigation Drawer
body: <p>I am trying to use the <a href="https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing" rel="noreferrer">Navigation Architecture Component</a> (NavHostFragment) with a <a href="https://developer.android.com/training/implementing-navigation/nav-drawer" rel="noreferrer">Navigation Drawer</a> (widget.NavigationView). I get one of the following two errors.</p>
  
  <p>1) This can happen when selecting an item from the drawer several times:</p>
  
  <p><code>java.lang.IllegalArgumentException: navigation destination app.myDomain.navdrawertrials:id/action_rootFragment_to_settingsFragment is unknown to this NavController</code></p>
  
  <p>2) This happens from my real code base that is set up the same way as the simplified sample below AFAICT. Why would a current navigation node not be set?</p>
  
  <p><code>java.lang.IllegalStateException: no current navigation node</code></p>
  
  <p><strong>Simplified Code</strong></p>
  
  <p>MainActivity</p>
  
  <pre><code>class MainActivity : AppCompatActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.main_activity)
  
          setupToolbar()
          setupNavDrawer()
          setupNavigation()
      }
  
  
      private fun setupToolbar() {
          setSupportActionBar( toolbar )
      }
  
      private fun setupNavigation() {
          val navController = findNavController( R.id.nav_host_fragment)
  
          setupActionBarWithNavController( navController, main_activity_drawer_layout )
      }
  
      private fun setupNavDrawer() {
          val toggle = ActionBarDrawerToggle(
                  this,
                  main_activity_drawer_layout,
                  toolbar,
                  R.string.navigation_drawer_open,
                  R.string.navigation_drawer_close)
  
          main_activity_drawer_layout.addDrawerListener(toggle)
          toggle.syncState()
  
  
          nav_drawer.setNavigationItemSelectedListener {
              val navController = findNavController( R.id.nav_host_fragment )
  
              when (it.itemId) {
                  R.id.nav_drawer_root_menu_item     -&gt; navController.navigate(R.id.rootFragment)
                  R.id.nav_drawer_first_menu_item    -&gt; navController.navigate(R.id.action_rootFragment_to_firstFragment)
                  R.id.nav_drawer_settings_menu_item -&gt; navController.navigate(R.id.action_rootFragment_to_settingsFragment)
              }
  
              main_activity_drawer_layout.closeDrawer(GravityCompat.START)
  
              true
          }
      }
  
      override fun onSupportNavigateUp() = findNavController(R.id.nav_host_fragment).navigateUp()
  }
  </code></pre>
  
  <p>main_activity.xml</p>
  
  <pre><code>&lt;android.support.v4.widget.DrawerLayout
      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:id="@+id/main_activity_drawer_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;include
          layout="@layout/main_activity_content"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
      &lt;android.support.design.widget.NavigationView
          android:id="@+id/nav_drawer"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:fitsSystemWindows="true"
          app:headerLayout="@layout/nav_drawer_header"
          app:menu="@menu/nav_drawer_menu" /&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>nav_drawer_menu.xml</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;item
          android:id="@+id/nav_drawer_root_menu_item"
          android:title="To Root" /&gt;
      &lt;item
          android:id="@+id/nav_drawer_first_menu_item"
          android:title="To First" /&gt;
      &lt;item
          android:id="@+id/nav_drawer_settings_menu_item"
          android:title="To Settings" /&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p>main_activity_content.xml</p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout
      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"
      tools:context=".MainActivity"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary" /&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;fragment
          android:id="@+id/nav_host_fragment"
          android:name="androidx.navigation.fragment.NavHostFragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:navGraph="@navigation/nav_graph"
          app:defaultNavHost="true"
          /&gt;
  
      &lt;android.support.design.widget.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom|end"
          android:layout_margin="@dimen/fab_margin"
          app:srcCompat="@android:drawable/ic_dialog_email" /&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>nav_graph.xml</p>
  
  <pre><code>&lt;navigation 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:id="@+id/nav_graph"
      app:startDestination="@id/rootFragment"&gt;
  
      &lt;fragment
          android:id="@+id/rootFragment"
          android:name="app.anytune.navdrawertrials.RootFragment"
          android:label="root_fragment"
          tools:layout="@layout/root_fragment" &gt;
          &lt;action
              android:id="@+id/action_rootFragment_to_firstFragment"
              app:destination="@id/firstFragment" /&gt;
          &lt;action
              android:id="@+id/action_rootFragment_to_settingsFragment"
              app:destination="@id/settingsFragment" /&gt;
      &lt;/fragment&gt;
      &lt;fragment
          android:id="@+id/firstFragment"
          android:name="app.anytune.navdrawertrials.FirstFragment"
          android:label="first_fragment"
          tools:layout="@layout/first_fragment" /&gt;
      &lt;fragment
          android:id="@+id/settingsFragment"
          android:name="app.anytune.navdrawertrials.SettingsFragment"
          android:label="settings_fragment"
          tools:layout="@layout/settings_fragment" /&gt;
  &lt;/navigation&gt;
  </code></pre>
  
  <p>root_fragment.xml (other nodes are similar empty fragments with just a label)</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".RootFragment"&gt;
  
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:text="Root Fragment" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>