I'm learning Kotlin Coroutines and I'm trying to build a simple app with some API requests. Unfortunately I've stumbled upon an error which is not really talkative, this is all I have in the logs:
FATAL EXCEPTION: main
Process: com.tests.myapp, PID: 14743
This is my simple coroutine which would simply call an API endpoint. I've copied the syntax from this tutorial.
CoroutineScope(Dispatchers.Main).launch {
API.call().registration();
}
For Kotlin Coroutines I use this version:
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
And for the networking library I have Retrofit like this:
object API {
private const val BASE_URL = "http://my-test-url-comes-here.com"
private val okHttpClient = OkHttpClient()
.newBuilder()
.addInterceptor(RequestInterceptor)
.build()
private fun getClient(): Retrofit =
Retrofit.Builder()
.client(okHttpClient)
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
fun call(): Endpoints {
return getClient().create(Endpoints::class.java)
}
}
Any insights?
try/catchinsidelaunchand log the exceptionEndpoints.ktfile look like?withContext(Dispatchers.IO)everywhere. In their example, the function fetches a lot of data but doesn’t process it. It’s trivial to pass some references around, even if the reference is to a large object.