且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

谷歌地图碎片返回null片段内

更新时间:2023-12-03 17:32:22

这个问题发生在我身上时,我试图端口我的Eclipse项目到Android Studio项目。

This issue happened to me when I tried to port my Eclipse project to Android Studio project.

java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap com.google.android.gms.maps.SupportMapFragment.getMap()' on a null object reference

我用它与一个片段活动是这样的:

I used it with a Fragment Activity like this:

((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.mapToday)).getMap();

然而,问题是,前面我使用谷歌播放服务的特定版本(4.3.23)。

However, the problem was, earlier I was using a specific version of Google Play Services (4.3.23).

不过摇篮打造选择最新的版本(编译com.google.android.gms:玩-服务:+')

But the Gradle build select the most recent version (compile 'com.google.android.gms:play-services:+')

我尝试了一些其他的特定版本一样(71年6月1日)。但还是给了零点例外。

I tried some other specific version like (6.1.71). But still gave null point exception.

我用同样的旧版本,因为我之前用和它的工作。

I used the same old version as I used before and it worked.

compile 'com.google.android.gms:play-services:4.3.23'

这对我的作品作为一种临时解决方案。然而,这将是一个问题,当我需要更新到 新戏服务库。

This works for me as a temporary solution. However, this will be a problem when I need to update to a new play services library.

看来,有没有具体的图库与此版本适用于摇篮建设 当我尝试这样的:

It seems that there is no specific map library with this version available for Gradle build when I try like this:

compile 'com.google.android.gms:play-services-maps:4.3.23'