Specify the language of the codelab if it is not English:
In which task and step of the codelab can this issue be found?
In the Android Basic with compose > Connect to the internet > Get data > Get data from the internet template .
Describe the problem
I found that when i was implementing this following function
private val retrofit = Retrofit.Builder()
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.baseUrl(BASE_URL)
.build()
by adding this line of code and import its library" .addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))"
and after that when i run my app then it crashes without opening . so, i go to logcat and ask that error with gemni ai then it says that Retrofit is unable to create a converter for the List type returned by the MarsApiService.getPhotos() method.
URL of codelab: https://developer.android.com/codelabs/basic-android-kotlin-compose-getting-data-internet?authuser=2&continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-5-pathway-1%3Fauthuser%3D2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-getting-data-internet#7
Specify the language of the codelab if it is not English:
In which task and step of the codelab can this issue be found?
In the Android Basic with compose > Connect to the internet > Get data > Get data from the internet template .
Describe the problem
I found that when i was implementing this following function private val retrofit = Retrofit.Builder() .addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) .baseUrl(BASE_URL) .build()
and after that when i run my app then it crashes without opening . so, i go to logcat and ask that error with gemni ai then it says that Retrofit is unable to create a converter for the List type returned by the MarsApiService.getPhotos() method.
then it sugget to use
import retrofit2.converter.gson.GsonConverterFactory
private val retrofit = Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create()) .baseUrl(BASE_URL) .build()
before this in the dependencies of gradle build module add implementation("com.squareup.retrofit2:converter-gson:2.11.0")
after doing this now it works properly
Steps to reproduce?
Versions Android Studio version: Android Studio Jellyfish API version of the emulator: API Level 34
Additional information Include screenshots if they would be useful in clarifying the problem.