这是我的相关代码:
import kotlinx.coroutines.experimental.*import kotlinx.coroutines.experimental.dispatchers.IOimport kotlinx.coroutines.experimental.dispatchers.Mainimport kotlin.coroutines.experimental.CoroutineContextimport kotlin.coroutines.experimental.suspendCoroutineclass Warehousesviewmodel(private val simRepository: SimRepository): BaseReactviewmodel<WarehousesVIEwData>(),Coroutinescope {private val job = Job()overrIDe val coroutineContext: CoroutineContext get() = job + MainoverrIDe val initialVIEwData = WarehousesVIEwData(emptyList())overrIDe fun onActiveVIEw() { launch { val warehouses = async(IO) { loaDWarehouses() }.await() updateVIEwData(vIEwData.value.copy(items = warehouses)) }}private suspend fun loaDWarehouses(): List<Warehouse> = suspendCoroutine {continuation -> simRepository.getWarehouses(object : SimDataSource.LoaDWarehousesCallback { overrIDe fun onWarehousesLoaded(warehouses: List<Warehouse>) { Timber.d("Loaded warehouses") continuation.resume(warehouses) } overrIDe fun onDatanotAvailable() { Timber.d("No available data") continuation.resume(emptyList()) } }) }}
我的问题是我得到一个运行时异常:
java.lang.IllegalStateException: Module with Main dispatcher is missing. Add dependency with required Main dispatcher,e.g. 'kotlinx-coroutines-androID'
我已将这些添加到我的gradle中:
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.1'implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-androID:0.26.0'
我对此有点新鲜,有人能帮帮我吗?
解决方法 Tim Castelijns说,使用相同的kotlinx-coroutines版本解决了这个问题.所以在我的情况下:implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.1'implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-androID:0.30.1'总结
以上是内存溢出为你收集整理的android – 缺少主调度程序的模块全部内容,希望文章能够帮你解决android – 缺少主调度程序的模块所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)