后端内部错误:代码生成期间的异常

时间:2019-08-02 17:00:39

标签: android kotlin retrofit kotlin-coroutines

我要关闭手机的互联网连接时遇到异常

Cannot evaluate the expression: : Backend Internal error: Exception during code generation
Cause: Can not generate outer receiver value for class <closure-StartViewModel$fetchCurrentWeek$1>

打开互联网后,一切正常!

异常出现在函数fetchCurrentWeek上

val currentWeek = WeekSource(ApiFactory.rozkladKpiApi).getCurrentWeek()

StartViewModel.kt

package andy.schedulekpi.ui.fragments.start

import android.content.SharedPreferences
import androidx.lifecycle.MutableLiveData
import andy.schedulekpi.network.api.ApiFactory
import andy.schedulekpi.network.sources.GroupSource
import andy.schedulekpi.network.sources.SourcesFactory
import andy.schedulekpi.network.sources.WeekSource
import andy.schedulekpi.ui.fragments.base.BaseViewModel
import andy.schedulekpi.utils.SHARED_PREFERENCES_GROUP
import kotlinx.coroutines.*

class StartViewModel : BaseViewModel() {
    // TODO: Implement the ViewModel

    private val source = SourcesFactory.weekSource

    val mCurrentWeek : MutableLiveData<Int> = MutableLiveData()

    fun fetchCurrentWeek() {
        scope.launch {
            val currentWeek = WeekSource(ApiFactory.rozkladKpiApi).getCurrentWeek()
            mCurrentWeek.postValue(currentWeek)
        }
    }

    fun getGroupFromSharedPreferences(sharedPreferences: SharedPreferences) : String {
        return sharedPreferences.getString(SHARED_PREFERENCES_GROUP, "null")!!
    }

    fun isGroupCachedInSharedPreferences(sharedPreferences: SharedPreferences) : Boolean {
        return sharedPreferences.contains(SHARED_PREFERENCES_GROUP)
    }


}

图片: 调试器图片:https://ibb.co/fNSLZZM

0 个答案:

没有答案