HiltClassCastException xxxDaggerBaseApplication_HiltComponents_SingletonC cannot be cast to xxMain

Posted guangdeshishe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HiltClassCastException xxxDaggerBaseApplication_HiltComponents_SingletonC cannot be cast to xxMain相关的知识,希望对你有一定的参考价值。

问题:

项目接入Hilt后编译时报ClassCastException错误:

Caused by: java.lang.ClassCastException: com.agile.base.DaggerBaseApplication_HiltComponents_SingletonC$ActivityRetainedCImpl$ActivityCImpl cannot be cast to com.example.myapplication.MainActivity_GeneratedInjector
        at com.example.myapplication.Hilt_MainActivity.inject(Hilt_MainActivity.java:67)
        at com.example.myapplication.Hilt_MainActivity$1.onContextAvailable(Hilt_MainActivity.java:38)
        at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99)
        at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:322)
        at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
        at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:22)

原因:

BaseApplication存在另一个模块中

解决办法:

将BaseApplication移到主项目模块中

以上是关于HiltClassCastException xxxDaggerBaseApplication_HiltComponents_SingletonC cannot be cast to xxMain的主要内容,如果未能解决你的问题,请参考以下文章

Python 正确有效地获取 DBUS 对象路径(例如 /org/bluez/dev_XX_XX_XX_XX_XX_XX/playerY)

如何使用 IP 范围引用所有 IP,例如XX.XX.XX.XX / 24 [关闭]

HTTPConnectionPool(host='xx.xx.xx.xx', port=xx): Max retries exceeded with url:(Caused by Co

微信小程序时钟(xx年xx月xx日xx:xx格式)

Zabbix聚合检测

HTTP的response code 1xx,2xx,3xx,4xx,5xx分别代表什么