Problem loading Maps v2

Asked

Viewed 96 times

0

Good morning!

I have the following code to load the map in my application:

if (mMap == null){
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    if(null == mMap)
    {
        SupportMapFragment fragment = SupportMapFragment.class.cast(getSupportFragmentManager().findFragmentById(R.id.map));
        fragment.onCreate(savedInstanceState);
        fragment.getMapAsync(this);
    }
}

XML:

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

Apparently, the tests worked correctly, there was no error loading, but I’m getting several failures in the google play.:

java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.maps.model.LatLng com.google.android.gms.maps.model.MarkerOptions.b' on a null object reference
    at com.google.maps.api.android.lib6.d.et.a(Unknown Source)
    at com.google.android.gms.maps.internal.j.onTransact(SourceFile:167)
    at android.os.Binder.transact(Binder.java:395)
    at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addMarker(Unknown Source)
    at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)

The NullPointerException occurs because, when trying to add the Marker to the map, it is null.

I treated the problem so that the NullPointerException, but would like to know why the map is not loaded?

From what I noticed, occur in all versions of Android (from 4.0 to 5.1), It is nothing specific of a version.

There are other ways to load the map?

Thanks in advance !

Greetings

1 answer

1


it is nice that you use getLastLocation to recover the value of your position, also check if the gps is enabled and by the way of doubt, creates a Latlng obj with the value "0,0", probably he is trying to create the Mark in the Activity onCreate, this causes it to pick up the null object before it can get a valid location, anything give a look at the link (Getting the Last Location - Android)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.