Mapbox-gl-native: [Android] Mapzen crash - NullPointerException

Created on 15 May 2017  ·  39Comments  ·  Source: mapbox/mapbox-gl-native

Platform: Android 7.0
Mapbox SDK version: 5.1.0-beta2

Steps to trigger behavior

  1. Create simple Map example
  2. Set My Location enabled
  3. Exit app

Actual behavior

When using 5.1.0-beta.2 there is a crash on close. Even when I create example project and set:

mMapboxMap.getMyLocationViewSettings().setEnabled(true);
mMapboxMap.setMyLocationEnabled(true);

After I close app I get a NullPointerException related to mapzen.

java.lang.NullPointerException: Attempt to invoke interface method 'com.mapzen.android.lost.api.LocationAvailability com.mapzen.android.lost.internal.IFusedLocationProviderService.getLocationAvailability()' on a null object reference
                                                                            at com.mapzen.android.lost.internal.FusedLocationProviderApiImpl$1$1.run(FusedLocationProviderApiImpl.java:51)
                                                                            at android.os.Handler.handleCallback(Handler.java:751)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                            at android.os.Looper.loop(Looper.java:154)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:6776)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

I haven't noticed it before (stable 5.0.2) now it's very common - sometimes it takes few seconds to get it. I'm not able to reproduce it when MyLocation is disabled.

If it's duplicated or known issue feel free to close, but I guess it's another blocker for stable 5.1.0 version.

Android crash

Most helpful comment

Thanks for creating an issue! We have merged a fix for this. Please refresh your dependencies and rebuild.

All 39 comments

For me the same at 5.1.0-beta2. I also get the java.lang.NullPointerException at com.mapzen.android.lost.api.LocationAvailability com.mapzen.android.lost.internal.IFusedLocationProviderService.getLocationAvailability()'

This also appears when I use com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-SNAPSHOT@aar

Thank you, it looks like an issue with the latest version of LOST. We've reported it to https://github.com/mapzen/lost/issues/198.

Thanks for creating an issue! We have merged a fix for this. Please refresh your dependencies and rebuild.

Thanks for working on this issue. At which dependency do you merged this fix?
com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-beta.2@aar
or
com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-SNAPSHOT@aar
?

This has shipped as a trigger to https://github.com/mapbox/mapbox-gl-native/pull/9046 and is available in com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-SNAPSHOT@aar. Thank you @mrfaa for following up!

I tried the fix and it works. But only when i have mapboxMap.setMyLocationEnabled(true). When I set mapboxMap.setMyLocationEnabled(false) to false it crashes with the above noted crash from @mpuchala .

same here, I get the crash when mapboxMap.setMyLocationEnabled(false)

THE LATEST SNAPSHOT IS WORKING FOR ME WITH LOCATION ENABLED. REJOICE! HALLELUJAH! THANK YOU!

@mrfaa @pamartineza I am unable to reproduce what you are seeing. I've pushed my sample code to this branch for reference.

Could you provide me with more information? Exactly which calls are you making to the Mapbox sdk and in what order? If there is any sample or pseudo code you can provide, that would also be helpful. Thank you.

@Emeritus-DarranKelinske Great, thanks for testing!

@sarahlensing thank for following up. I'm including mapbox in my project like mentioned in https://www.mapbox.com/android-sdk/ with all the lifecycle methods.

When the map is ready (onMapReady) I'm requesting the following methods on my mapbox map:
mapboxMap = map; mapboxMap.setStyleUrl(xxx); mapboxMap.getUiSettings().setCompassEnabled(false); mapboxMap.getUiSettings().setAttributionTintColor(xxx); mapboxMap.getUiSettings().setRotateGesturesEnabled(false); mapboxMap.getUiSettings().setTiltGesturesEnabled(false); mapboxMap.setMyLocationEnabled(true); mapboxMap.getMyLocationViewSettings().setForegroundTintColor(xxx); mapboxMap.getMyLocationViewSettings().setAccuracyAlpha(0); mapboxMap.setMinZoomPreference(xxx); mapboxMap.setMaxZoomPreference(xxx); mapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(xxx)

@mrfaa @pamartineza I'm unable to reproduce it as well - are you sure you cleared your dependencies and use newest SNAPSHOT build?

@sarahkleins @tobrun
Guys, I have another problem - when MyLocation is enabled after I close app there is still GPS active (it's not a problem when it's disabled). It's probably not related issue, but it looks very similar to this one: https://github.com/mapbox/mapbox-gl-native/issues/8683

I've tried to disable Location in onStop(), onPause() and onDestroy - like in your example @sarahkleins but unfortunately without success. I'll try to debug it, but I guess it's another thing we should focus on.

@mpuchala I have just cleared my dependencies and today with the SNAPSHOT build the crash is gone. :)

Hey @mpuchala

Guys, I have another problem - when MyLocation is enabled after I close app there is still GPS active (it's not a problem when it's disabled).

Thank you for reaching out and reporting your problem.
Could you add some more information for reproducing the issue in a new ticket?

Capturing from above that this issue is resolved, thank you all for helping out!

@mpuchala i use the newest SNAPSHOT com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-SNAPSHOT@aar and refreshed all my dependencies. It works works everything fine. But when i set mapboxMap.setMyLocationEnabled(false) it crashes with the NPE at lost.api.LocationAvailability. However i will use mapbox only with setMyLocationEnabled to true, so its not a problem for me. Does anyone notice this behavior too?

I'm using Android 7.0 with targetSdkVersion 25, compileSdkVersion 25 and buildToolsVersion 25.0.2

I have this same issue when setting to false.

On May 22, 2017 12:18 PM, "Fabian" notifications@github.com wrote:

@mpuchala https://github.com/mpuchala i use the newest SNAPSHOT
com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-SNAPSHOT@aar and refreshed
all my dependencies. It works works everything fine. But when i set
mapboxMap.setMyLocationEnabled(false) it crashes with the NPE at
lost.api.LocationAvailability. However i will use mapbox only with
setMyLocationEnabled to true, so its not a problem for me.

I'm using Android 7.0 with targetSdkVersion 25, compileSdkVersion 25 and
buildToolsVersion 25.0.2


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/mapbox/mapbox-gl-native/issues/8999#issuecomment-303163851,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AP9KIvoSvXtceGZLVSL7x4r_Ktb3v5zBks5r8cMbgaJpZM4Na6a5
.

Thank you to everyone working on this project! <3

@tobrun Where in the Mapbox SDK are location updates removed?

I see LocationSource#removeLocationUpdates but can't find any place where its called. When setMyLocationEnabled(false) is called it looks like the LocationSource's engine listener is removed and then the source is deactivated:

locationSource.removeLocationEngineListener(userLocationListener);
locationSource.deactivate();

We introduced a change with this PR which simplifies what happens when a client disconnects. Before this PR, location updates would be removed on disconnect, but after, they no longer are. So, if you aren't removing location updates, it would make sense that you see this crash. Hope this helps, let me know what you find!

Thank you for :eyes: @sarahlensing, you are correct, this is fixed with https://github.com/mapbox/mapbox-gl-native/pull/9099 and resolves https://github.com/mapbox/mapbox-gl-native/issues/9068. Note that I haven't been able to produce the null pointer mentioned by others. Would love if someone above with the crash could verify if #9099 resolves this issue as well or provide some additional context. Thanks again to all for helping out!

@tobrun Good job, I havent notice above bug, but right now app crashes from different reason. This happen really often on Samsung Note 3 (Android 5.1.1):

java.lang.IllegalStateException: Location update received after client was disconnected. Did you forget to unregister location updates before disconnecting?
at com.mapzen.android.lost.internal.FusedLocationServiceCallbackManager.onLocationChanged(FusedLocationServiceCallbackManager.java:31)
at com.mapzen.android.lost.internal.FusedLocationProviderApiImpl$1$1.run(FusedLocationProviderApiImpl.java:46)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5938)
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:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

CUSTOM_DATA=
PHONE_MODEL=SM-N9005
BRAND=samsung
ANDROID_VERSION=5.0

@krsticdragan Thank you for reaching out and reporting your problem.

As @sarahlensing pointed out:

if you aren't removing location updates, it would make sense that you see this crash

It's detailed in the _Upgrade Notes_ section of Lost 3.0.0 release notes:

Because location updates are no longer unregistered when a client disconnects, it is essential that developers explicitly unregister them

You're getting the exception defined here.

@Guardiola31337 Thanks, I unregister it and manage to fix it up 👍

@krsticdragan I also get the crash at
java.lang.IllegalStateException: Location update received after client was disconnected. Did you forget to unregister location updates before disconnecting? at com.mapzen.android.lost.internal.FusedLocationServiceCallbackManager.onLocationChanged(FusedLocationServiceCallbackManager.java:31)

I'm using the newest com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-SNAPSHOT@aar version.

@mrfaa did you try above comment?
It seems the same issue that @krsticdragan was experiencing.

@Guardiola31337 Thanks, you are right. I saw that @tobrun noted that this is fixed in #9099 and will be available in Release Android v5.1.0-beta.3 #9114 :-)

@mrfaa You will need to remove LocationEngineListener manually. I did it by using removeLocationEngineListener(locationEngineListener) in onDestroy() method, it should fix the issue.

@krsticdragan @mrfaa what components are you using to get Location data? If you are solely relying on MyLocationView with MapboxMap#setMyLocationEnabled(true) then the exception should not occur. If you are requesting location events yourself, you will need to comply to the rules set out in https://github.com/mapbox/mapbox-gl-native/issues/8999#issuecomment-303524365. Thank you all for following up on this issue so closely!

@tobrun I only use MapboxMap#setMyLocationEnabled(true) to show the user position on the map. I'm not using private LocationEngine locationEngine; or other mapbox functions to get a user position like used in the BasicUserLocation.java Demo.

I have implemented my own "FusedLocationProviderService" by using the Google FusedLocationProviderApi, where i handle the user location for other purposes in my app.

@tobrun I tought that was the issue with setMyLocationEnabled method. Currently Im using LocationManager and only setMyLocationEnabled(true). Testing out the application right now with the LocationEngineListener and it seems to occur when switching from one map back to the previous one in two different activities even I created and remove LocationEngineListener.

@mrfaa I had the same problem. And in my project I do not need to use map box positioning and LOSTApi (i use Google api for positioning). Now I have changed mapbox shared preferences and fix this problem.

TelemetryUtils.getSharedPreferences(mainActivity).edit().putBoolean(TelemetryConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_ENABLED, false).apply();

@giperwlad Are you using setMyLocationEnabled method? I tried your solution and unfortunatly that didnt fix it.

@krsticdragan . I don't call setMyLocationEnabled method. I I do not need to use map box positioning.

Try to change shared preferences before calling Mapbox.getInstance() method

@tobrun Is it a problem when I implemented my own FusedLocationProvider in my project? Do I have to handle mapbox specific?

My thought is, that the issue java.lang.IllegalStateException: Location update received after client was disconnected. Did you forget to unregister location updates before disconnecting? at com.mapzen.android.lost.internal.FusedLocationServiceCallbackManager.onLocationChanged(FusedLocationServiceCallbackManager.java:31) is fixed within #9099 and will be available in Release Android v5.1.0-beta.3 #9114. Is this right?

Thanks for following up!

@giperwlad Thanks for a hint, but that didnt work, just manage to reproduce a bug. @mrfaa I switched to 5.1.0-beta.3 and bug is still there.

Still getting it on

compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-beta.3@aar') {
    transitive = true
}

The issue is that sometimes an activity / app doesn't close gracefully and the next time it starts back up the app crashes with this:

05-31 11:03:24.592 8741-8741/com.laelaps.collar.ui E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.laelaps.collar.ui, PID: 8741
java.lang.IllegalStateException: Location update received after client was disconnected. Did you forget to unregister location updates before disconnecting?
at com.mapzen.android.lost.internal.FusedLocationServiceCallbackManager.onLocationChanged(FusedLocationServiceCallbackManager.java:31)
at com.mapzen.android.lost.internal.FusedLocationProviderApiImpl$1$1.run(FusedLocationProviderApiImpl.java:46)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6918)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

When you open it the next time, this exception does not happen.

Been debugging this today myself and also hit the exception that @Emeritus-DarranKelinske has by rotating the device 10-20 times. I'm looking into this more if this is something that needs to be fixed from our end or LOST.

I can confirm, that I'm getting this crash with 5.1.0-beta.3 and mapbox-android-services:2.1.1@aar.

Due specific business needs I'm trying not to use (actually I'm not using) mapbox provided tracking mode and instead I'm using google maps LocationServices.FusedLocationApi by myself.

I'm going to close this issue, so we have more clarity on the milestone related to the LOST issue. I'm opting to track this in #9139 as we have a PR tackling that in https://github.com/mapbox/mapbox-gl-native/pull/9142. In this PR we working on resolving the current outstanding upstream issues (https://github.com/mapzen/lost/issues/213). Thank you all for chipping in, continuing this issue in #9139.

@tobrun Sir,how can i disable the mapbox in onpause and ondistroy method ??

Was this page helpful?
0 / 5 - 0 ratings