You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

报错‘Cannot access '<init>': it is package-private in 'Icon'’的原因分析

报错原因分析
  • 类混淆与参数缺失引发的匹配错误:你导入的是Compose Material3的androidx.compose.material3.Icon组件,但在BottomAppBar的IconButton中,仅传入Icons.Filled.Edit这一个参数,未指定contentDescription参数。此时编译器未匹配到需要至少两个参数的Compose Icon组件,反而错误匹配了Android原生的android.graphics.drawable.Icon类:
    • Cannot access '<init>': it is package-private in 'Icon':原生Icon的构造方法为包私有,外部无法直接实例化
    • Too many arguments for public/*package*/ constructor Icon() defined in android.graphics.drawable.Icon:原生Icon的构造方法不接受你传入的ImageVector类型参数,参数数量与类型均不匹配
  • FloatingActionButton中Icon无报错的原因:该Icon同时传入了Icons.Default.Add和contentDescription = "Add"两个参数,编译器正确匹配到你导入的Compose Material3 Icon组件,因此可正常运行。

内容的提问来源于stack exchange,提问作者Kalcifer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 06:46:02