Не могу пофиксить данную ошибку вот код проекта:
Data class
data class RickAndMorty(
val image: String,
val name: String,
)
Api interface
interface RickAndMortyApi {
@GET("/api/character")
suspend fun getRickAndMorty() : Response<List<RickAndMorty>>
}
RetrofitInstance
object RetrofitInstance {
val api : RickAndMortyApi by lazy {
Retrofit.Builder()
.baseUrl("https://rickandmortyapi.com")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(RickAndMortyApi::class.java)
}
}
CoroutineScope
lifecycleScope.launchWhenCreated {
binding.progressBar.isVisible = true
val response = try {
RetrofitInstance.api.getRickAndMorty()
} catch (e: IOException) {
Log.e(TAG, "IOException, you might not internet connection")
binding.progressBar.isVisible = false
return@launchWhenCreated
} catch (e: HttpException) {
Log.e(TAG, "HttpException, unexpected response")
binding.progressBar.isVisible = false
return@launchWhenCreated
}
if(response.isSuccessful && response.body() != null) {
adapter.rickAndMorty = response.body()!!
} else {
Log.e(TAG, "Response not successful")
}
binding.progressBar.isVisible = false
}