No virtual method elapsedNow-UwyO8pc()D in class Lkotlin/time/TimeMark; or its super classes (declaration of ‘kotlin.time.TimeMark’ appears in /data/app/~~8ToQ39W1Gmvz79om2S69_Q==/xxx.xx.xx-dvGHvg3f2zzmurhXBKmXeA==/base.apk!classes22.dex)
解决方法
把
androidLogger(Level.DEBUG)
改成
androidLogger(Level.NONE)
// 初始化 Koin
startKoin {
//androidLogger(Level.DEBUG)
androidLogger(Level.NONE)
androidContext(this@BaseApplication)
modules(listOf(netModule, viewModelModule, repositoryModule))
}
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Caused by: org.koin.core.error.InstanceCreationException: Could not create instance for [Factory:‘com.jiulang.wordsfairy.ui.page.main.home.HomeViewModel’]
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:62)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:36)…
报错定位在HomeViewModel
class HomeViewModel(
private val repository: PostRepository
) : BaseViewModel() {
}
在要为其创建实例的应用模块PostRepository
还要导入到Koin的Module里面
/** 数据仓库 Module */
val repositoryModule: Module = module {
factory { PostRepository(get()) }
}
val viewModelModule: Module = module {
viewModel { HomeViewModel(get()) }
}
最后初始化 Koin
startKoin {
//androidLogger(Level.DEBUG)
androidLogger(Level.NONE)
androidContext(this@BaseApplication)
modules(listOf(netModule, viewModelModule, repositoryModule))
}