Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapView onCreate throws NullPointerException on LG devices

First of all, this problem is for me only reproducible on LG devices (LG G4 and G5) running Android 6. The problem was introduced through the last update of the google play services. If I manually downgrade the google play services on my LG devices the error is gone. Unfortunately I cannot tell my users to do this, so I need to find another solution. As this error is reproducible with my app in the play store I can be certain the error was not introduced through my own code changes.

The error occurs through calling the onCreate() method inside MapView. I subclassed MapView and have my own class like this

public class MyMap extends MapView implements OnMapReadyCallback {
    ...
}

Inside the constructor of MyMap I call the onCreate method

public MyMap() {
    ...
    this.onCreate(null);
    this.onResume();
    this.getMapAsync(this);
    ...
}

On my LG devices running Android 6 this throws the following exception:

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources com.google.maps.api.android.lib6.impl.aq.e()' on a null object reference
at com.google.maps.api.android.lib6.gmm6.vector.ah.getResources(:com.google.android.gms.DynamiteModulesB:340)
at android.util.ResolutionOverride.<init>(ResolutionOverride.java:56)
at android.view.SurfaceView.init(SurfaceView.java:207)
at android.view.SurfaceView.<init>(SurfaceView.java:187)
at com.google.maps.api.android.lib6.gmm6.vector.am.<init>(:com.google.android.gms.DynamiteModulesB:1)
at com.google.maps.api.android.lib6.gmm6.vector.ah.<init>(:com.google.android.gms.DynamiteModulesB:3)
at com.google.maps.api.android.lib6.gmm6.api.am.<init>(:com.google.android.gms.DynamiteModulesB:53)
at com.google.maps.api.android.lib6.gmm6.api.am.a(:com.google.android.gms.DynamiteModulesB:49)
at com.google.android.gms.maps.internal.bv.a(:com.google.android.gms.DynamiteModulesB:38)
at com.google.maps.api.android.lib6.impl.az.a(:com.google.android.gms.DynamiteModulesB:80)
at com.google.maps.api.android.lib6.impl.az.a(:com.google.android.gms.DynamiteModulesB:1)
at com.google.maps.api.android.lib6.impl.cw.a(:com.google.android.gms.DynamiteModulesB:18)
at com.google.android.gms.maps.internal.t.onTransact(:com.google.android.gms.DynamiteModulesB:17)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.IMapViewDelegate$zza$zza.onCreate(Unknown Source)
at com.google.android.gms.maps.MapView$zza.onCreate(Unknown Source)
at com.google.android.gms.dynamic.zza$3.zzb(Unknown Source)
at com.google.android.gms.dynamic.zza$1.zza(Unknown Source)
at com.google.android.gms.maps.MapView$zzb.zzJy(Unknown Source)
at com.google.android.gms.maps.MapView$zzb.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onCreate(Unknown Source)
at com.google.android.gms.maps.MapView.onCreate(Unknown Source)

I found a similar problem with Airbnb's react native map, but their solution does not seem relevant to my problem. https://github.com/airbnb/react-native-maps/issues/1358

Any help or other ideas I could try out are much appreciated.

like image 850
PogoMips Avatar asked Jun 19 '17 06:06

PogoMips


1 Answers

You can try to use MapFragment instead of MapView because for updated google play services 11.0.55 not supporting MapView. I used MapView its worked for me.

Activity class:

    private SupportMapFragment mMapFragment; 

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //return inflater.inflate(R.layout.fragment_find_direction, container, false);
        View view = inflater.inflate(R.layout.fragment_find_direction, null, false);
        SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager()
                .findFragmentById(R.id.map_fragment);
        mMapFragment.getMapAsync(this);
        mMapFragment = mapFragment;
        return view;
    }

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
mMapFragment.onCreate(savedInstanceState);
}

Xml class:

<fragment
    class="com.google.android.gms.maps.SupportMapFragment"
    android:id="@+id/map_fragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/main_lay"
    android:apiKey="@string/google_map_key"
    android:clickable="true"
    android:enabled="true"
    android:focusable="true"
    app:layout_collapseMode="parallax">
</fragment>
like image 173
Sathish Kumar VG Avatar answered Nov 09 '22 19:11

Sathish Kumar VG