google-developer-training / android-basics-kotlin-mars-photos-app

Apache License 2.0
91 stars 193 forks source link

Android Basics: Get data from the Internet #169

Closed utsav7011 closed 8 months ago

utsav7011 commented 1 year ago

name: Android Basics Unit 4 issue about: Report problems with the Android Basics Unit 4 codelabs title: 'Android Basics Unit 4 issue:' labels: '' assignees: ''


URL of codelab

In which task and step of the codelab can this issue be found? Object declarations : Step 2 object MarsApi { val retrofitService : MarsApiService by lazy { retrofit.create(MarsApiService::class.java) } }

Describe the problem Not able to declare use the property retorfit inside the object and it throws an error for the same, instead of creating the singleton object, the retrofit object can be created in the companion object with no errors I guess.

Like This : companion object { private const val BASE_URL = "https://android-kotlin-fun-mars-server.appspot.com"

    private val moshi = Moshi.Builder()
        .add(KotlinJsonAdapterFactory()).build()

    val retrofit = Retrofit.Builder()
        .addConverterFactory(MoshiConverterFactory.create(moshi))
        .baseUrl(Companion.BASE_URL).build().create(MarsApiService::class.java)
}

Steps to reproduce?

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

Versions Android Studio version: API version of the emulator:

Additional information Include screenshots if they would be useful in clarifying the problem.