摇篮依赖:
compile "com.google.android.gms:play-services-location:11.0.0"
compile "com.google.android.gms:play-services-places:11.0.0"
清单:
<menifest>
.
.
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application>
.
.
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</menifest>
爪哇:
private void showPlacePicker() {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
} catch ( GooglePlayServicesRepairableException e ) {
Log.d( "PlacesAPI Demo", "GooglePlayServicesRepairableException thrown" );
} catch ( GooglePlayServicesNotAvailableException e ) {
Log.d( "PlacesAPI Demo", "GooglePlayServicesNotAvailableException thrown" );
}
}
我也启用了Google Places API for Android
. 不要认为,api 密钥集成存在问题,因为我已经使用该密钥加载了谷歌地图。然而,只要showPlacePicker()
调用该方法;应用程序崩溃。
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.maps.api.android.lib6.impl.bn.o()' on a null object reference
at com.google.maps.api.android.lib6.impl.cw.b(:com.google.android.gms.DynamiteModulesB:26)
at com.google.android.gms.maps.internal.t.onTransact(:com.google.android.gms.DynamiteModulesB:21)
at android.os.Binder.transact(Binder.java:387)
at unt.b(:com.google.android.gms:1)
at ode.a(:com.google.android.gms:0)
at ocx.b(:com.google.android.gms:2)
at ocu.a(:com.google.android.gms:2)
at com.google.android.gms.maps.MapView.a(:com.google.android.gms:1)
at alox.onResume(:com.google.android.gms:2)
at com.google.android.chimera.FragmentProxy.onResume(:com.google.android.gms:0)