Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[Android] Mapzen crash - NullPointerException #8999

Closed
mpuchala opened this issue May 15, 2017 · 39 comments
Closed

[Android] Mapzen crash - NullPointerException #8999

mpuchala opened this issue May 15, 2017 · 39 comments
Labels
Android Mapbox Maps SDK for Android crash

Comments

@mpuchala
Copy link

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.

@mpuchala mpuchala changed the title Mapzen - NullPointerException [Android] Mapzen crash - NullPointerException May 15, 2017
@kkaefer kkaefer added Android Mapbox Maps SDK for Android crash labels May 15, 2017
@mrfaa
Copy link

mrfaa commented May 15, 2017

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

@zugaldia
Copy link
Member

Thank you, it looks like an issue with the latest version of LOST. We've reported it to lostzen/lost#198.

@sarahsnow1
Copy link

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

@mrfaa
Copy link

mrfaa commented May 19, 2017

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
?

@tobrun
Copy link
Member

tobrun commented May 19, 2017

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

@mrfaa
Copy link

mrfaa commented May 19, 2017

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 .

@pamartineza
Copy link

pamartineza commented May 19, 2017

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

@Emeritus-DarranKelinske

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

@sarahsnow1
Copy link

@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!

@mrfaa
Copy link

mrfaa commented May 22, 2017

@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)

@mpuchala
Copy link
Author

mpuchala commented May 22, 2017

@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: #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.

@pamartineza
Copy link

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

@Guardiola31337
Copy link
Contributor

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?

@tobrun
Copy link
Member

tobrun commented May 22, 2017

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

@mrfaa
Copy link

mrfaa commented May 22, 2017

@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

@Emeritus-DarranKelinske
Copy link

@tobrun tobrun reopened this May 22, 2017
@Emeritus-DarranKelinske

Thank you to everyone working on this project! <3

@sarahsnow1
Copy link

@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!

@tobrun
Copy link
Member

tobrun commented May 24, 2017

Thank you for 👀 @sarahlensing, you are correct, this is fixed with #9099 and resolves #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!

@krsticdragan
Copy link

@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

@Guardiola31337
Copy link
Contributor

Guardiola31337 commented May 26, 2017

@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.

@krsticdragan
Copy link

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

@mrfaa
Copy link

mrfaa commented May 29, 2017

@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.

@Guardiola31337
Copy link
Contributor

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

@mrfaa
Copy link

mrfaa commented May 30, 2017

@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 :-)

@krsticdragan
Copy link

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

@tobrun
Copy link
Member

tobrun commented May 30, 2017

@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 #8999 (comment). Thank you all for following up on this issue so closely!

@mrfaa
Copy link

mrfaa commented May 30, 2017

@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.

@krsticdragan
Copy link

@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.

@giperwlad
Copy link

@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();

@krsticdragan
Copy link

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

@giperwlad
Copy link

@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

@mrfaa
Copy link

mrfaa commented May 30, 2017

@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!

@krsticdragan
Copy link

@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.

@Emeritus-DarranKelinske
Copy link

Emeritus-DarranKelinske commented May 31, 2017

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.

@tobrun
Copy link
Member

tobrun commented May 31, 2017

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.

@ragaisis
Copy link

ragaisis commented Jun 6, 2017

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.

@tobrun
Copy link
Member

tobrun commented Jun 7, 2017

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 #9142. In this PR we working on resolving the current outstanding upstream issues (lostzen/lost#213). Thank you all for chipping in, continuing this issue in #9139.

@rajputneeru
Copy link

rajputneeru commented Sep 5, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android crash
Projects
None yet
Development

No branches or pull requests