getMap()为某些设备抛出NullPointerException

时间:2016-04-05 19:53:01

标签: java android google-maps

我正在尝试在我的应用程序中膨胀MapFragment但最近,它已开始在某些设备(主要是三星设备)上投掷NullPointerException。我活动中的代码是

if (map == null) {
    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}

在我的XML中,我使用

定义片段
<fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

有没有人有理由说这可能会在某些设备上崩溃而不是其他设备?

1 个答案:

答案 0 :(得分:0)

也许是Android故障。在Android Marshmallow 6.0及更高版本中,您需要请求权限,在清单中添加它是不够的。