Android Studio集成Google Maps打开地图Activity时应用崩溃如何解决?
问题原因及解决方案
崩溃日志已经明确指向核心错误:java.lang.IllegalArgumentException: Binary XML file line #12: Duplicate id 0xffffffff, tag null, or parent id 0x7f0900d2 with another fragment for com.google.android.gms.maps.SupportMapFragment,即SupportMapFragment重复加载,结合你提供的配置,共两处需要修复:
- 修复地图页面布局的嵌套错误
你当前的地图布局中,外层<fragment>已经声明为SupportMapFragment,内部又嵌套了一个完全相同的SupportMapFragment,属于冗余嵌套,直接删除内层的fragment即可,修改后正确的布局代码如下:
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MapsActivity"/>
- 修复AndroidManifest的权限拼写错误
你声明的定位权限android.permission.ACCESS_FINE_LOCATION末尾多写了一个句号,会导致权限申请不生效,后续如果使用定位相关功能也会出现异常,修改为:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
- 可选校验项
如果你修改应用名称的同时也修改了应用包名,需要确认你使用的Google Maps API Key是否已经绑定了当前的包名和签名,否则后续地图加载会出现空白问题。
内容的提问来源于stack exchange,提问作者Randie Culli Vega
相关产品推荐
相关产品推荐

