Unresolved refernce ( success, error) while trying to use TOMTOM search api in kotlin app

110 Views Asked by At

I'm trying to use TOMTOM search API in my kotlin application

Here is my code :

    private fun testSearch() {

        val observer = object : DisposableSingleObserver<FuzzySearchResponse>() {
            val text = "cairo"
            val search = FuzzySearchQueryBuilder.create(text).build()
            override fun onSuccess(fuzzySearchResponse: FuzzySearchResponse) {
                search.success(fuzzySearchResponse.results)
            }

            override fun onError(throwable: Throwable) {
                search.error(null, Error(throwable.message))
            }
        }
    }

added API to AndroidManfist.xml and initialized tomtom search in my Gradle file

as shown in the image, the IDLE can't find both reference error or success.

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

Your IDE can't find a reference because you are looking for it inside a FuzzySearchQuery object instead of the SearchApi object which is not defined in your code at all. Please find a solution in below (slightly modified) function:

private fun testSearch() {

    val searchApi = OnlineSearchApi.create(applicationContext)!!
    val text = "cairo"
    val searchQuery = FuzzySearchQueryBuilder.create(text).build()

    val observer = object: DisposableSingleObserver<FuzzySearchResponse>() {
        override fun onSuccess(t: FuzzySearchResponse) {
            for (r in t.results) {
                Toast.makeText(applicationContext, r.address.freeformAddress, Toast.LENGTH_SHORT).show()
            }
        }
        override fun onError(e: Throwable) {
            Toast.makeText(applicationContext, "err", Toast.LENGTH_SHORT).show()
        }
    }
    searchApi.search(searchQuery).subscribeWith(observer)
}