Giter VIP home page Giter VIP logo

mvvmnewsapp's People

Contributors

philipplackner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mvvmnewsapp's Issues

postValue null

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())
}

}

`

Unable to resolve host "newsapi.org": No address associated with hostname

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

java.lang.IllegalArgumentException: Unable to create converter for class com.androiddevs.mvvmnewsapp.ui.pojo.NewsResponse

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
)

error

Compiler giving " Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option " error
to NewsViewModelProviderFactory class

inflating error

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

postValue null

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())
}

}

`

Empty recycler view

When the internet was down, and after it comes back, there is no way to refresh the empty recycler view.

Error occured in chapter 7

Where I get an error

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!!

Kotlin android extensions vs. view bindings

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.