gpt4 book ai didi

kotlin - Hilt Activity必须附加到@AndroidEntryPoint应用程序

转载 作者:行者123 更新时间:2023-12-02 13:16:19 30 4
gpt4 key购买 nike

该应用一安装即崩溃,并引发上述奇怪的错误。
我已经注释了如下所示的事件及其子片段。

@AndroidEntryPoint
class HomeActivity : AppCompatActivity() {
companion object{
lateinit var currentUser: User
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_home)
val navController = Navigation.findNavController(this, R.id.home_nav)
val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottom_navigation)
bottomNavigationView.setupWithNavController(navController)
fetchCurrentUser()
}
还附加了Application类,该类是根据文档使用Hilt的每个应用程序所必需的
@HiltAndroidApp
class CoreApplication:Application()
和崩溃的日志
Caused by: java.lang.IllegalStateException: Hilt Activity must be attached to an @AndroidEntryPoint Application. Found: class androidx.multidex.MultiDexApplication
at dagger.hilt.android.internal.managers.ActivityComponentManager.createComponent(ActivityComponentManager.java:82)
at dagger.hilt.android.internal.managers.ActivityComponentManager.generatedComponent(ActivityComponentManager.java:65)
at com.example.vcare.home.Hilt_HomeActivity.generatedComponent(Hilt_HomeActivity.java:43)
at com.example.vcare.home.Hilt_HomeActivity.inject(Hilt_HomeActivity.java:62)
at com.example.vcare.home.Hilt_HomeActivity.onCreate(Hilt_HomeActivity.java:37)
at com.example.vcare.home.HomeActivity.onCreate(HomeActivity.kt:27)
at android.app.Activity.performCreate(Activity.java:7224)
at android.app.Activity.performCreate(Activity.java:7213)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)

最佳答案

解决此问题的方法是:在AndroidManifest.xml文件的android:name = ".CoreApplication"标记中声明<application .../>

关于kotlin - Hilt Activity必须附加到@AndroidEntryPoint应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64006085/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com