philipplackner / mvvmnewsapp Goto Github PK
View Code? Open in Web Editor NEWNews App Tutorial on YouTube
News App Tutorial on YouTube
When the internet was down, and after it comes back, there is no way to refresh the empty recycler view.
Press the save button as many times as the news goes to the saves page. Once pressed it shouldn't be over and over again. Help please
After I search once, I enter a new query, and new articles load at the end of the previous search results.
I am getting this error, Checked on Stackoverflow but didn't get any solution for it.
My files
NewsResponse.kt
package com.androiddevs.mvvmnewsapp.ui.pojo
data class NewsResponse(
val articles: List<Article>,
val status: String,
val totalResults: Int
)
Article.kt
package com.androiddevs.mvvmnewsapp.ui.pojo
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(
tableName = "articles"
)
data class Article(
@PrimaryKey(autoGenerate = true)
var id: Int? = null,
val author: String,
val content: String,
val description: String,
val publishedAt: String,
val source: Source,
val title: String,
val url: String,
val urlToImage: String
)
im getting
Caused by: android.view.InflateException: Binary XML file line #25 in com.androiddevs.mvvmnewsapp:layout/activity_news: Binary XML file line #25 in com.androiddevs.mvvmnewsapp:layout/activity_news: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #25 in com.androiddevs.mvvmnewsapp:layout/activity_news: Error inflating class fragment
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property viewModel has not been initialized
at com.androiddevs.mvvmnewsapp.ui.NewsActivity.getViewModel(NewsActivity.kt:15)
at com.androiddevs.mvvmnewsapp.ui.fragments.BreakingNewsFragment.onViewCreated(BreakingNewsFragment.kt:25)
and app crashes
Compiler giving " Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option " error
to NewsViewModelProviderFactory class
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())
}
}
`
Getting this error when Navigating from breaking news screen to article screen
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())
}
}
`
Architectural Skeleton - MVVM News App Around 4:00
NewsActivity.kt. (onCreate function.)
override fun onCreate(SavedInstanceState: Bundle?){
......
val repository = NewsRepository(ArticleDatabase(this)
# In this line following error occured.
/*
Error
Type mismatch.
Required: ArticleDatabase
Found:Unit
*/
}
I changed 'invoke' function in ArticleDatabase.kt as follows and it seems works without snag(I don't know it is right way or not though....)
operator fun invoke (context:Context) : ArticleDatabase {
return instance ?: synchronized(LOCK){
instance ?: createDatabase(context).also{ instance = it }
}
Thank you for your awesome videos and great instruction!!
Hi Philipp,
not really an issue but sth that I do not really understand. I'd like to use view bindings instead of the kotlin android extensions. When I try to transfer the example, I have issues to integrate the bindings into the fragments. Do you have a tutorial to look at?
Thank you for your great work btw!
Internet permission is given, API key is generated but still getting the error
HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "newsapi.org": No address associated with hostname
Though the link gets called successfully (receives required data) in the browser but in the android studio, it throws the above error
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.