The method toMediaType() of the class MediaType is unknown, when using import okhttp3.MediaType as written in the code snippet.
For newer versions of OkHttp the method is contained in a Companion of the class MediaType.
Steps to reproduce?
Go to the second code snippet under Update MarsApiService and MarsViewModel.
Try to initialize the variable retrofit: The method toMediaType() used for conversion of the string value is not known, when using the given import statement.
Possible solution
Change the import statement in the code snippet of the codelab to import okhttp3.Companion.toMediaType and update the modules build.gradle with a newer version of OkHttp, e.g. by including implementation "com.squareup.okhttp3:okhttp:4.10.0".
URL of codelab:
Get data from the internet
In which task and step of the codelab can this issue be found?
In Parse the JSON response with kotlinx.serialization under Update MarsApiService and MarsViewModel.
Describe the problem
toMediaType()
of the classMediaType
is unknown, when usingimport okhttp3.MediaType
as written in the code snippet.Companion
of the classMediaType
.Steps to reproduce?
retrofit
: The methodtoMediaType()
used for conversion of the string value is not known, when using the given import statement.Possible solution
Change the import statement in the code snippet of the codelab to
import okhttp3.Companion.toMediaType
and update the modulesbuild.gradle
with a newer version of OkHttp, e.g. by includingimplementation "com.squareup.okhttp3:okhttp:4.10.0"
.Versions