title: Error while adding click listeners to the menu items of a navigation drawer using View Binding
body: <p>When I try to add click listeners to the menu items using <code>binding.navigationView.setNavigationItemSelectedListener</code>, it throws me an error saying <strong>Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type NavigationView?</strong></p>
  <p>So when I add the safe call like this: <code>binding.navigationView?.setNavigationItemSelectedListener</code>, naturally the click listener doesn't work, neither do i get my toast message on clicking on the menu items nor does the fragment I've added in the dashboard menu item work.</p>
  <p>When I add the non null asserted call, the app altogether crashes and gives me <strong>nullPointerException</strong> in the logcat.</p>
  <p>Here is the kotlin code:</p>
  <pre><code>class MainActivity : AppCompatActivity() {
  private lateinit var binding: ActivityMainBinding
  
  override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          binding = ActivityMainBinding.inflate(layoutInflater)
          setContentView(binding.root)
          setUpToolbar()
  
          val actionBarDrawerToggle = ActionBarDrawerToggle(          
              this@MainActivity,
              binding.root,
              R.string.open_drawer,
              R.string.close_drawer)
          binding.root.addDrawerListener(actionBarDrawerToggle)       
          actionBarDrawerToggle.syncState()
  
          binding.navigationView.setNavigationItemSelectedListener {
  
              when(it.itemId){
                  R.id.dashboard -&gt; {
                      supportFragmentManager.beginTransaction()
                      .replace(R.id.frameLayout, DashboardFragment())
                      .commit()
  
                  binding.drawerLayout.closeDrawers()
                  }
                  R.id.favourites -&gt; {
                      Toast.makeText (
                          this@MainActivity,
                          &quot;Clicked on favourites&quot;,
                          Toast.LENGTH_LONG
                      ).show()
                  }
                  R.id.profile -&gt; {
                      Toast.makeText (
                          this@MainActivity,
                          &quot;Clicked on profile&quot;,
                          Toast.LENGTH_LONG
                      ).show()
                  }
                  R.id.aboutApp -&gt; {
                      Toast.makeText (
                          this@MainActivity,
                          &quot;Clicked on about&quot;,
                          Toast.LENGTH_LONG
                      ).show()
                  }
              }
  
              return@setNavigationItemSelectedListener true
          }
  
  
      }
  
      fun setUpToolbar(){
          supportActionBar?.title = &quot;Toolbar Title&quot;               
          supportActionBar?.setHomeButtonEnabled(true)            
          supportActionBar?.setDisplayHomeAsUpEnabled(true)      
      }
      override fun onOptionsItemSelected(item: MenuItem): Boolean {     
          val id = item.itemId                                            
          if(id == android.R.id.home){                                    
              binding.root.openDrawer(GravityCompat.START)               
          }
          return super.onOptionsItemSelected(item)
      }
  }
  </code></pre>
  <p>here is the xml code:</p>
  <pre><code>&lt;androidx.drawerlayout.widget.DrawerLayout 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:id=&quot;@+id/drawerLayout&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
      
  
  &lt;androidx.coordinatorlayout.widget.CoordinatorLayout
      android:id=&quot;@+id/coordinatorLayout&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;&gt;
  
      &lt;androidx.appcompat.widget.Toolbar
          android:id=&quot;@+id/toolbar&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:minHeight=&quot;?attr/actionBarSize&quot;
          android:background=&quot;@color/design_default_color_primary_dark&quot;
          android:theme=&quot;@style/ThemeOverlay.AppCompat.Dark&quot;/&gt;
  
      &lt;FrameLayout
          android:id=&quot;@+id/frameLayout&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;fill_parent&quot;/&gt;
  
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  
      &lt;com.google.android.material.navigation.NavigationView
          android:id=&quot;@+id/navigationView&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          app:headerLayout=&quot;@layout/drawer_header&quot;
          app:menu=&quot;@menu/menu_drawer&quot;
          android:layout_gravity = &quot;start&quot;/&gt;
  
  &lt;/androidx.drawerlayout.widget.DrawerLayout&gt;
  </code></pre>
  <p>It'd be great if someone could point out where I'm going wrong</p>