首页 > 其他分享> > 【Hilt】ClassCastException xxxDaggerBaseApplication_HiltComponents_SingletonC cannot be cast to xxMain
【Hilt】ClassCastException 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移到主项目模块中
标签:java,SingletonC,xxxDaggerBaseApplication,Hilt,MainActivity,myapplication,com,exa 来源: https://blog.csdn.net/guangdeshishe/article/details/122672796