Error: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $ **
Activity : MainActivity.kt
fun getData() {
apiCall().apiService.getData()
.enqueue(object : Callback<DataModalItem> {
override fun onResponse(
call: Call<DataModalItem>,
response: Response<DataModalItem>
) {
Log.e("CHECK_RES", "onResponse: " + response.body()?.punchline)
}
override fun onFailure(call: Call<DataModalItem>, t: Throwable) {
Log.e("CHECK_RES", "Error: " + t.localizedMessage)
Toast.makeText(this@MainActivity, "Error"+t.localizedMessage, Toast.LENGTH_SHORT).show()
}
})
Retrofit Class ---> apiCall.kt
val BASE_URL = "https://official-joke-api.appspot.com"
private val retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
val apiService by lazy {
retrofit.create(apiService::class.java)
}
Interface ---> apiService.kt
@GET("/jokes/random/25")
fun getData(): Call<DataModalItem>
I try to solve this Error , so anyone have solution of this error please let me know.
Source: View source