这是完整的错误:e:C:\ Users \ HP \ AndroidStudioProjects \ MoneyManager \ app \ src \ main \ java \ com \ cruxrepublic \ moneymanager \ ui \ auth \ LoginActivity.kt:(22,28):
表达式“kodein”不能作为函数调用。找不到函数“invoke()”
这是错误中提到的代码块。我通常是依赖注入(inject)的新手,我将不胜感激
class LoginActivity() : AppCompatActivity(), AuthListener, KodeinAware {
override val kodein by kodein()
private val factory by instance<AuthViewModelFactory>()
private lateinit var authViewModel: AuthViewModel
private lateinit var binding: ActivityLoginBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding= DataBindingUtil.setContentView(this,R.layout.activity_login)
authViewModel = ViewModelProvider(this,factory).get(AuthViewModel::class.java)
binding.authViewModel = authViewModel
authViewModel.authListener = this
}
最佳答案
我通过更改import for Kodein解决了这个问题,以前是:import org.kodein.di.kodein。
我将其更改为:import org.kodein.di.android.kodein
关于android - 如何解决此Kodein错误:无法将 'kodein'表达式作为函数调用。找不到函数 'invoke()',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62566511/