You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I followed your instructure but I get this error
Attempt to invoke virtual method 'void androidx.lifecycle.MutableLiveData.postValue(java.lang.Object)' on a null object reference
I checked everything but I couldn't find the problem
my code
`
class NewsViewModel(
private val newsRepository: NewsRepository
) : ViewModel() {
val breakingNews: MutableLiveData<Resource<NewsResponse>> = MutableLiveData()
private var breakingNewsPage = 1
init {
getBreakingNews("us")
}
private fun getBreakingNews(countryCode: String) = viewModelScope.launch {
breakingNews.postValue(Resource.Loading())
val response = newsRepository.getBreakingNews(countryCode, breakingNewsPage)
breakingNews.postValue(handleBreakingNewsResponse(response))
}
private fun handleBreakingNewsResponse(response: Response<NewsResponse>) : Resource<NewsResponse> {
if(response.isSuccessful) {
response.body()?.let { resultResponse ->
return Resource.Success(resultResponse)
}
}
return Resource.Error(response.message())
}
}
`
The text was updated successfully, but these errors were encountered:
I followed your instructure but I get this error
Attempt to invoke virtual method 'void androidx.lifecycle.MutableLiveData.postValue(java.lang.Object)' on a null object reference
I checked everything but I couldn't find the problem
my code
`
class NewsViewModel(
private val newsRepository: NewsRepository
) : ViewModel() {
}
`
The text was updated successfully, but these errors were encountered: