0
votes

I'm working on this app that shows popular movies. I got this Log: "/results: retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall@9daee07". I got everything done but I don't get any result in my RecyclerView. I don't know how to display data that I fetched. This is url: http://api.themoviedb.org/3/movie/popular?api_key=api_key_goes_here.

MovieResponse.kt

data class MovieResponse(
    val page: Int,
    val results: List<Movie>,
    @SerializedName("total_pages") val totalPages: Int,
    @SerializedName("total_results") val totalResults: Int
)

Movie.kt

data class Movie(
    val id: Int,
    val overview: String,
    val popularity: Double,
    @SerializedName("poster_path") val posterPath: String,
    @SerializedName("release_date") val releaseDate: String,
    val title: String,
    @SerializedName("vote_average") val voteAverage: Double
)

MainAdapter.kt

package com.example.sloomena.ui

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.sloomena.R
import com.example.sloomena.data.MovieResponse
import kotlinx.android.synthetic.main.movie_details_row.view.*

class MainAdapter: RecyclerView.Adapter<CustomHolder>(){

    val movies: MutableList<MovieResponse> = mutableListOf()

    fun refreshData(newResults: List<MovieResponse>) {
        movies.clear()
        movies.addAll(newResults)
        notifyDataSetChanged()
    }

    override fun getItemCount(): Int {
        return movies.size
    }

    override fun onBindViewHolder(holder: CustomHolder, position: Int) {
        holder.bind(movies.get(position))
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomHolder {
        val layoutInflater = LayoutInflater.from(parent?.context)
        val cellForRow =  layoutInflater.inflate(R.layout.movie_details_row, parent, false)
        return CustomHolder(cellForRow)
    }
}
class CustomHolder(itemView: View): RecyclerView.ViewHolder(itemView){
    fun bind(movie: MovieResponse) {

        itemView.title.text = movie.results.toString()
    }
}

thmdbAPI.kt

interface tmdbAPI {

    @GET("movie/popular")
    fun getPopularMovies(
        @Query("api_key") api_key: String
    ): Call<List<MovieResponse>>
}

Networking.kt

const val BASE_URL = "http://api.themoviedb.org/3/"

object Networking{
    val showSearchService: tmdbAPI = Builder()
        .addConverterFactory(ConverterFactory.converterFactory)
        .client(HttpClient.client)
        .baseUrl(BASE_URL)
        .build()
        .create(tmdbAPI::class.java)
}
object ConverterFactory{
    val converterFactory = GsonConverterFactory.create()
}
object HttpClient{
    val client = OkHttpClient.Builder()
        .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
        .build()
}

MainActivity.kt

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        setUpUi()
        findMovies()
    }

    private fun setUpUi() {
        id_recyclerview.layoutManager = LinearLayoutManager(this)
        id_recyclerview.adapter = MainAdapter()
    }

    private fun findMovies() {
        GlobalScope.launch(Dispatchers.Main) {
            val results = Networking.showSearchService.getPopularMovies("api_key_goes_here")
            Log.d("results", results.toString())
        }}
}

In my movie_details_row.xml I have (id_picture_movie, id_movie_realise_date and title). Also, I don't know how to get properties in List(Movie) inside of MovieResponse.

2
please include the full error - Rafa
there is no error, only my log show this '* * * retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall@9daee07' - Marina

2 Answers

0
votes

You aren't actually passing back any items to display after you've set up your recyclerview. So what you're doing is setting it up, sending a network request, and then you do nothing with that data.

val mainAdapter = MainAdapter()
...

private fun findMovies() {
        GlobalScope.launch(Dispatchers.Main) {
            val results = Networking.showSearchService.getPopularMovies("0b0e8d104f0d6130a4fc67848f89e107")
            Log.d("results", results.toString())

            //Assuming you're returning a list 
            mainAdapter.refreshData(results)
        }}
}
0
votes

1) If I were you, I would edit your post to exclude your API key. Take your response and paste in on a site like Pastebin. In the future, try to paste the stacktrace of the error as well as it makes the answers' life much easier.

2) In your response data classes you may need to have @SerializedName for your other values. It's been awhile since I have used Gson as my deserializer, so perhaps that is incorrect. This is likely the reason for this "Also, I don't know how to get properties in List(Movie) inside of MovieResponse."

3) Your return type for the API service is wrong. Here is the result of the API call formatted: https://pastebin.com/TQb0YSty. You can see that the return type is not a list, it is a single JSON object. So your return type of Call<List<MovieResponse>> should be Call<MovieResponse>. This may be what is resulting in the ExecutorCallbackCall error.

There may be other issues, but those are the things that stood out to me right away