Closed ImAbhishekTomar closed 5 years ago
It's hard to say without seeing your code, and this probably isn't the best place to ask your question because you're building a different app. But near the top of your error message I'm seeing ANR_LOG which mentions something about taking too long to execute. Does this help? https://stackoverflow.com/questions/51435390/runnable-is-not-being-executed-completely-after-the-delay-is-over-from-handlers
Here is my code sample
SEARCH Response Root Class
data class SearchResponse(
val context: Context, //If I disable this line the code is working
val items: List<Item>, //If I disable this line the code is working
val kind: String,
val queries: Queries,
val searchInformation: SearchInformation,
val url: Url
)
API Configuration CODE
interface GoogleApiService {
@GET("v1")
fun getSearchResult(
@Query("q") searchQuery:String,
@Query("cx") searchEngineId:String="017576662512468239146:omuauf_lfve"
) : Deferred<SearchResponse>
companion object {
operator fun invoke(): GoogleApiService{
val requestInterceptor=Interceptor{ chain ->
val url=chain.request()
.url()
.newBuilder()
.addQueryParameter("key",GOOGLE_API_KEY)
.build()
val request=chain.request()
.newBuilder()
.url(url)
.build()
return@Interceptor chain.proceed(request)
}
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(requestInterceptor)
.build()
return Retrofit.Builder()
.client(okHttpClient)
.baseUrl("https://www.googleapis.com/customsearch/")
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(GoogleApiService::class.java)
}
}
API CALL
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProviders.of(this).get(SearchViewModel::class.java)
// TODO: Use the ViewModel
val apiService=GoogleApiService()
GlobalScope.launch(Dispatchers.Main) {
val searchResponce = apiService.getSearchResult("lectures").await()
txtMain.text=searchResponce.toString()
}
}
My partial error is resolved when I convert my List
JSON
Current Class
data class SearchResponse(
val context: Context, //If I enable this line thro error
val items: ArrayList<Item>, //If I enable this line thro error
val kind: String,
val queries: Queries,
val searchInformation: SearchInformation,
val url: Url
)
data class Context(
val facets: ArrayList<Any>, //This is showing error.....
val title: String
)
data class Any(
val anchor: String,
val label: String,
@SerializedName("label_with_op")
val labelWithOp: String
)
Hello,
Kindly please help me on this issue I am using the same pattern as (@ResoCoder) your weather app. Thanks for sharing great tutorials.
Note: This is working when I remove all List
ERROR
MY JSON FORMAT