我要关闭手机的互联网连接时遇到异常
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