起因是用了android studio自动生成的 Bottom Navigation Activity,结果运行报错,最后在外网找到了原因,是最开始我把style配置文件里设置了NoActionBar,所以setTitle的时候就会找不到ActionBar,然后报错,最后改回来就可以了。第二种方法是把中间那句注释掉。
方法一:
改前:
改后:
方法二:注释掉中间的代码
原文:Sounds like you have a theme set for your Activity that has .NoActionBar.
A safer solution to using the action bar is to use a Toolbar as part of your layout, then use setupWithNavController(Toolbar toolbar, NavController navController, AppBarConfiguration configuration)
If you do want to use an action bar, then your Activity needs a theme that provides an ActionBar. Check your AndroidManifest.xml and styles.xml.
原文链接:https://stackoverflow.com/questions/58861123/why-does-my-app-crash-invoking-setupactionbarwithnavcontrollernavcontroller-a