google-developer-training / basic-android-kotlin-compose-training-mars-photos

Solution code for Android Basics in Kotlin course
https://developer.android.com/courses/android-basics-kotlin/course?gclid=CjwKCAjw4c-ZBhAEEiwAZ105RTyT-iaLHzrhMBUXdMhO230ZDwOwxxI2x4RgK8DwBxK8t1h0wmU_QxoCi4YQAvD_BwE
Apache License 2.0
66 stars 54 forks source link

Get Data from the Internet #150

Open akmaurya7 opened 2 months ago

akmaurya7 commented 2 months ago

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

   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.

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?

  1. Go to...
  2. Click on...
  3. See error...

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.