I've got the following ViewModel:
class FundamentalsViewModel: ViewModel() {
var fundamentalsLiveData = MutableLiveData<WrappedResult<DataResponse>>()
private val repository = FundamentalsRespository()
private var job: Job? = null
fun getData(type: String) {
if(job == null || job?.isActive == false) {
fundamentalsLiveData.value = WrappedResult.Loading
job = viewModelScope.launch(Dispatchers.IO) {
try {
val response = repository.getData(type)
withContext(Dispatchers.Main) {
fundamentalsLiveData.value = WrappedResult.Success(response)
}
} catch(e: Exception) {
withContext(Dispatchers.Main) {
fundamentalsLiveData.value = WrappedResult.Failure(e)
}
}
}
}
}
}
Everything works perfectly in-house, but out in the field I'm getting Crashylitics reports that say this: "Fatal Exception: java.lang.NullPointerException Parameter specified as non-null is null: method kotlin.j0.d.u.p, parameter symbol" on the line that is:
fundamentalsLiveData.value = WrappedResult.Loading
There is no other information in the crash log. How is it possible that there is any NPE here? The WrappedResult is a typical Kotlin sealed class that looks like this:
sealed class WrappedResult<out T> {
data class Success<out T: Any>(val data:T) : WrappedResult<T>()
data class Failure(val error: Throwable) : WrappedResult<Nothing>()
data class CallFailure(val error: String) : WrappedResult<Nothing>()
object Loading : WrappedResult<Nothing>()
}