android - 解析 Koin 类的实例时出错

标签 android koin

帮助解决问题!(((我有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/

相关文章:

android - Koin依赖注入(inject)本地和远程数据源之间的切换

java - 链接多个 Transformations.switchMap 关闭一个 LiveData 源

android - Koin vs Kodein - 依赖注入(inject)你更喜欢什么? Kotlin

android - 尝试使用 koin 但在 android 上无法正常工作

java - 如何防止 "Firestore, Provided document path must not be null"错误?

kotlin - Ktor 与 Koin DI 无法注入(inject),缺少 clazz

android - Mysterious Signal 11 在访问 Room 数据库时崩溃

android - 谷歌云功能 : edit Firebase node at a specific time

java - 在 PC 上运行的用于监听 Android 设备的 Bluez 应用程序

android - 在android中创建自定义通知