Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setTitle

本文解决了在使用Android Studio自动生成的BottomNavigationActivity时遇到的运行时报错问题。错误原因是主题设置中包含了NoActionBar,导致setTitle方法无法找到ActionBar。提供了解决方案,包括修改主题设置或注释相关代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

起因是用了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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值