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

Apache License 2.0
92 stars 193 forks source link

Android Basics: Get data from the Internet #104

Closed athithya-np closed 10 months ago

athithya-np commented 2 years 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 https://developer.android.com/codelabs/basic-android-kotlin-training-getting-data-internet?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-4-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-getting-data-internet#7

In which task and step of the codelab can this issue be found? Task: Parse the JSON response with Moshi Step: 5th step under "Update MarsApiService and OverviewViewModel"

Describe the problem When we ask the Retrofit to return a list of MarsPhoto objects from the JSON array using List<MarsPhoto> we get a warning of "This class shouldn't be used in Kotlin. Use kotlin.collections.List or kotlin.collections.MutableList instead." And due to this warning we cannot pass the size property to listResult variable in getMarsPhotos() method in the later step. Thus making it impossible to complete this codelab.

I fixed this issue by using Array<MarsPhoto> instead of List<MarsPhoto>. Also by using Array, I was able to get the size of the listResult in getMarsPhotos() method.

Steps to reproduce?

  1. Go to interface MarsApiService and set the type of fun getPhotos() to List<MarsPhoto>
  2. List<MarsPhoto> gets highlighted with the warning "This class shouldn't be used in Kotlin. Use kotlin.collections.List or kotlin.collections.MutableList instead."

Versions Android Studio version: Artic Fox 2020.3.1 Patch 3 API version of the emulator: used a physical device running Android 9

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