帮助解决问题!(((我有3个DI模块。natworkModule中有一个改造对象,viewModelModule中有所有viewModel,respositoryModule中有对服务器的所有请求。我按照文档做了一切,但是我在 Google 中找不到此错误。提前谢谢您!!!抱歉我的英语!)
class App : Application(){
override fun onCreate() {
super.onCreate()
startKoin(this, listOf(natworkModule, viewModelModule,repositoryModule))
}
}
var natworkModule = module {
single { createOkHttpClient() }
single { createApiService<ApiService>(get () ,getProperty(SERVER_URL))
}
}
const val SERVER_URL = "https://api.github.com/"
fun createOkHttpClient() : OkHttpClient{
val httpLoggingInterceptor = HttpLoggingInterceptor()
httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BASIC
return OkHttpClient.Builder()
.connectTimeout(60L, TimeUnit.SECONDS)
.readTimeout(60L, TimeUnit.SECONDS)
.addInterceptor(httpLoggingInterceptor).build()
}
inline fun <reified T> createApiService(okHttpClient: OkHttpClient, url: String): T {
val retrofit = Retrofit.Builder()
.baseUrl(url)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(LiveDataCallAdapterFactory()).build()
return retrofit.create(T::class.java)
}
var repositoryModule = module {
factory<TestRepository> {
TestRepositoryImpl(get())
}
}
var viewModelModule = module {
viewModel {
TestViewModel(get())
}
}
最佳答案
问题出在这个常数值 -> SERVER_URL =“https://api.github.com/” 科因找不到它。因此有一个异常(exception)。感谢大家!!!
关于android - 解析 Koin 类的实例时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53248547/