I'm trying to get GoogleMap on Android API 23 but following line gives me null and that's weird, because there was no problem on API 22 or maybe last build of Google Play Services.
GoogleMap mMapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map_view)).getMap();
And the layout:
<fragment
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginTop="15dp"
class="com.google.android.gms.maps.MapFragment" />
Log
09-03 07:15:52.128 4540-4540/com.XXX E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.XXX, PID: 4540,
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.XXX/com.XXX.activities.ShopNewActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.UiSettings com.google.android.gms.maps.GoogleMap.getUiSettings()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.UiSettings com.google.android.gms.maps.GoogleMap.getUiSettings()' on a null object reference
at com.XXX.activities.ShopNewActivity.onCreate(ShopNewActivity.java:211)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Checkout this snippet as commented by Brad:
OnMapReadyCallback interface.In onCreate() method add the following code to get the GoogleMap asynchronously once it's ready:
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Once the map is ready to be used you will get a callback thru onMapReady() in which GoogleMap is accessible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With