尝试在 kotlin 应用程序中使用 TOMTOM 搜索 api 时未解决的引用(成功、错误)
Unresolved refernce ( success, error) while trying to use TOMTOM search api in kotlin app
我正在尝试在我的 kotlin 应用程序中使用 TOMTOM 搜索 API
这是我的代码:
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))
}
}
}
将 API 添加到 AndroidManfist.xml
并在我的 Gradle
文件中初始化了 tomtom 搜索
如图所示,IDLE找不到引用错误或成功。
您的 IDE 找不到引用,因为您在 FuzzySearchQuery
对象而不是根本未在您的代码中定义的 SearchApi
对象中查找它。请在下面(稍作修改)函数中找到解决方案:
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)
}
我正在尝试在我的 kotlin 应用程序中使用 TOMTOM 搜索 API
这是我的代码:
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))
}
}
}
将 API 添加到 AndroidManfist.xml
并在我的 Gradle
文件中初始化了 tomtom 搜索
如图所示,IDLE找不到引用错误或成功。
您的 IDE 找不到引用,因为您在 FuzzySearchQuery
对象而不是根本未在您的代码中定义的 SearchApi
对象中查找它。请在下面(稍作修改)函数中找到解决方案:
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)
}