Я пытаюсь связать навигационный ящик, но каждый раз появляется сообщение об ошибке
this my MainsActivity
class MainActivity : AppCompatActivity() {
lateinit var appBarConfiguration:AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navController = findNavController(R.id.my_nav_host_fragment)
val drawerLayout=findViewById<DrawerLayout>(R.id.drawer_layout)
appBarConfiguration = AppBarConfiguration(navController.graph,drawerLayout)
NavigationUI.setupActionBarWithNavController(this,navController,drawerLayout)
NavigationUI.setupWithNavController(findViewById<NavigationView>(R.id.nav_view),navController)
}
override fun onSupportNavigateUp(): Boolean {
val navController = this.findNavController(R.id.my_nav_host_fragment)
return NavigationUI.navigateUp(navController, appBarConfiguration)
}
}
И это ошибка
Process: com.example.navigationdrawer, PID: 15945
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.navigationdrawer/com.example.navigationdrawer.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.setTitle(java.lang.CharSequence)' on a null object reference
Серьезно не могу понять, в чем ошибка?