Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a message when retrieving data from the API (data not found), besides showing the data in one place it, it works #891

Closed
riluq opened this issue Aug 20, 2019 · 2 comments

Comments

@riluq
Copy link

riluq commented Aug 20, 2019

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.riluq.moviecatalogue, PID: 31900
    com.squareup.moshi.JsonDataException: Expected an int but was 55213641c3a3684dd4003c55 at path $.created_by[0].credit_id
        at com.squareup.moshi.JsonUtf8Reader.nextInt(JsonUtf8Reader.java:921)
        at com.squareup.moshi.StandardJsonAdapters$7.fromJson(StandardJsonAdapters.java:173)
        at com.squareup.moshi.StandardJsonAdapters$7.fromJson(StandardJsonAdapters.java:171)
        at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:137)
        at com.riluq.moviecatalogue.data.entities.model.CreatedByJsonAdapter.fromJson(CreatedByJsonAdapter.kt:31)
        at com.riluq.moviecatalogue.data.entities.model.CreatedByJsonAdapter.fromJson(CreatedByJsonAdapter.kt:12)
        at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:137)
        at com.squareup.moshi.CollectionJsonAdapter.fromJson(CollectionJsonAdapter.java:76)
        at com.squareup.moshi.CollectionJsonAdapter$2.fromJson(CollectionJsonAdapter.java:53)
        at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:137)
        at com.riluq.moviecatalogue.data.entities.DetailsTvShowResponseJsonAdapter.fromJson(DetailsTvShowResponseJsonAdapter.kt:75)
        at com.riluq.moviecatalogue.data.entities.DetailsTvShowResponseJsonAdapter.fromJson(DetailsTvShowResponseJsonAdapter.kt:20)
        at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:137)
        at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:45)
        at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:27)
        at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:223)
        at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:121)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
class DetailTvShowViewModel(idTvShow: Int, application: Application): AndroidViewModel(application) {

    private var viewModelJob = Job()
    private val coroutineScope = CoroutineScope(viewModelJob + Dispatchers.Main)

    private val _detailTvShow = MutableLiveData<DetailsTvShowResponse>()
    val detailTvShow: LiveData<DetailsTvShowResponse>
        get() = _detailTvShow

    private val _navigateToHomepage = MutableLiveData<Boolean>()
    val navigateToHomepage: LiveData<Boolean>
        get() = _navigateToHomepage

    init {
        getDetailTvShow(idTvShow)
    }

    private fun getDetailTvShow(idTvShow: Int) {
        coroutineScope.launch {
            val getDetailTvShowDeferred = Api.retrofitService.getDetailTvShowAsync(tvId = idTvShow)
            try {
                val listResult = getDetailTvShowDeferred.await()
                if (listResult.nameDetailsTvShow != null) {
                    _detailTvShow.value = listResult
                }
            } catch (t: IOException) {
                Log.i("DetailTvShowViewModel", "message : ${t.message.toString()}")
                Log.i("DetailTvShowViewModel", "localizedMessage : ${t.localizedMessage}")
                Log.i("DetailTvShowViewModel", "printStackTrace : ${t.printStackTrace()}")
                _detailTvShow.value = null
            }
        }
    }

//    val displayGenreList: LiveData<String> = Transformations.map(detailTvShow) { response ->
//        val genreName = response.genresDetailsTvShow?.map { it.nameGenreMovie }
//        "Genre : ${genreName?.joinToString(separator = ", ")}"
//    }
//
//    val displayRating: LiveData<String> = Transformations.map(detailTvShow) {
//        "${it.ratingDetailsTvShow} Out of ${it.ratingCountDetailsTvShow} review"
//    }
//
//    val displayNumberOfSeason: LiveData<String> = Transformations.map(detailTvShow) {
//        it.numberOfSeasonsDetailsTvShow.toString()
//    }
//    val displayNumberOfEpisodes: LiveData<String> = Transformations.map(detailTvShow) {
//        it.numberOfEpisodesDetailsTvShow.toString()
//    }

    fun onHomepageClicked() {
        _navigateToHomepage.value = true
    }

    fun onHomepageClickedComplete() {
        _navigateToHomepage.value = false
    }

    override fun onCleared() {
        super.onCleared()
        viewModelJob.cancel()
    }
}
@ZacSweers
Copy link
Collaborator

Hi @riluq - we can't assist with this without knowing more about the code. Specifically - what is CreatedBy's shape? From the error, it sounds like it has a property credit_id that you have designated as an Int but is actually coming in json as a String

@ZacSweers
Copy link
Collaborator

Closing this for now, happy to revisit if the requested information's provided!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants