title: Switching between Fragment classes in Kotlin
body: <p>I have a Navigation drawer and have a problem in switching between fragments in android with kotlin. No error messages appear, but I guess the problem in this peace of code:</p>
  
  <pre><code>private fun selectItemDrawer(menuItem: MenuItem){
      var fragment:Fragment? = null
      var fragmentClass:Class&lt;*&gt; = when(menuItem.itemId)
      {
          R.id.first-&gt; FirstFragment::class.java
          R.id.second-&gt; SecondFragment::class.java
          R.id.third-&gt; ThirdFragment::class.java
          R.id.fourth-&gt; FourthFragment::class.java
          else -&gt; FirstFragment::class.java
      }
      try {
         fragment = fragmentClass.newInstance() as Fragment
      }catch (e:Exception){
          e.printStackTrace()
      }
  
      var fragmentManager = supportFragmentManager
      fragmentManager.beginTransaction()
              .replace(R.id.frame,fragment)
              .commit()
      menuItem.isChecked = true
      menuItem.title
      drawer_layout.closeDrawers()
  }
  </code></pre>
  
  <p>Could anyone help in this please!</p>