集成Google Place Autocomplete时PlaceSelectionListener匿名类报错如何解决
Google Place Autocomplete PlaceSelectionListener报错解决方案
问题根因
该报错为包导入不兼容导致,Google Places SDK已从旧版Google Play Services Location组件中独立,新旧版本的Place、PlaceSelectionListener类路径完全不同,你当前导入了旧版接口类,代码里实现的是新版方法签名,和接口要求不匹配,因此触发抽象方法未实现、override注解无效的错误。
解决步骤
- 检查Module级
build.gradle依赖配置,移除旧版Places依赖,仅保留新版独立SDK依赖:
需删除的旧依赖示例:implementation 'com.google.android.gms:play-services-places:xxx'
需添加的新版依赖(可替换为最新稳定版):implementation 'com.google.android.libraries.places:places:3.2.0' - 替换Java文件顶部所有相关import语句为新版包路径下的类导入:
import com.google.android.libraries.places.api.Places; import com.google.android.libraries.places.api.model.Place; import com.google.android.libraries.places.api.model.RectangularBounds; import com.google.android.libraries.places.api.model.TypeFilter; import com.google.android.libraries.places.api.net.PlacesClient; import com.google.android.libraries.places.widget.AutocompleteSupportFragment; import com.google.android.libraries.places.widget.listener.PlaceSelectionListener; import com.google.android.gms.common.api.Status; - 同步Gradle配置后清理IDE缓存:Android Studio点击
File → Invalidate Caches,勾选清理文件系统缓存选项后重启IDE,报错即可消失。
内容的提问来源于stack exchange,提问作者jseok
相关产品推荐
相关产品推荐

