mapbox / mapbox/mapbox-navigation-android
Crash: Attempt to invoke virtual method 'void com.mapbox.navigation.ui.MultiOnClickListener.clearListeners()' on a null object reference
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Kotlin
- Estrellas
- 651
- Forks
- 321
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
**Android API:**
Mapbox Navigation SDK version: **9.6.0** and Navigator **1.1.0** & **1.3.0**
### Steps to trigger behavior
1. Basically I'm using the sample from here https://docs.mapbox.com/android/navigation/guides/install/ (however it is converted into a different language).
2. Pause/Switch Application
### Expected behavior
No Crash
### Actual behavior
Crash
Appears to be like #1971, however the stack trace appears to be slightly different.
---
This occurs when I click the `Switch` application button (i.e. Square Nav Button); the app throws this error. I am logging all the events; and I see:
The Pause & Stop events in sequence, which I then chain to the MapBox Navigator onPause, onStop calls exactly like the demo. However about 1/2 a second after; I get the below stack trace crash.... I've also tried not sending the onStop, onPause, etc... No change...
Based on the callstack below; I suspect the issue is something has already called:
https://github.com/mapbox/mapbox-navigation-android/blob/master/libnavigation-ui/src/main/java/com/mapbox/navigation/ui/RecenterButton.java#L142-L146
And
https://github.com/mapbox/mapbox-navigation-android/blob/master/libnavigation-ui/src/main/java/com/mapbox/navigation/ui/RecenterButton.java#L144
This line I believe is actually invalid, as nothing in the code will re-create the MultiOnClickListener again in this element.
as it is only created during creation of it, so if this element is re-attached it will misbehave and crash later:
https://github.com/mapbox/mapbox-navigation-android/blob/master/libnavigation-ui/src/main/java/com/mapbox/navigation/ui/RecenterButton.java#L29
According to https://stackoverflow.com/a/65227045 & https://proandroiddev.com/make-your-custom-view-lifecycle-aware-its-a-piece-of-cake-90b7c0498686 it appears `onDetachFromWindow` is NOT the place to cleanup/null things like this, as the view can be re-attached **without** being re-created if used in things like tabs/pagers. So nulling the listener will lead to a crash if it is re-attached. In addition it might be good if you checked to verify that the `MultiOnClickListener` isn't null in the `clearListeners` function on line 143 as something obviously called this function a second time...
---
```
System.err: Attempt to invoke virtual method 'void com.mapbox.navigation.ui.MultiOnClickListener.clearListeners()' on a null object reference
System.err:
System.err: StackTrace:
System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.navigation.ui.MultiOnClickListener.clearListeners()' on a null object reference
System.err: at com.mapbox.navigation.ui.RecenterButton.clearListeners(RecenterButton.java:143)
System.err: at com.mapbox.navigation.ui.RecenterButton.onDetachedFromWindow(RecenterButton.java:135)
System.err: at android.view.View.dispatchDetachedFromWindow(View.java:19607)
System.err: at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3814)
System.err: at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806)
System.err: at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3806)
System.err: at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5431)
System.err: at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5402)
System.err: at android.view.ViewGroup.removeView(ViewGroup.java:5333)
System.err: at android.view.ViewOverlay$OverlayViewGroup.remove(ViewOverlay.java:216)
System.err: at android.view.ViewGroupOverlay.remove(ViewGroupOverlay.java:84)
System.err: at androidx.transition.ViewGroupOverlayApi18.remove(ViewGroupOverlayApi18.java:53)
System.err: at androidx.transition.Visibility$1.onTransitionEnd(Visibility.java:457)
System.err: at androidx.transition.Transition.end(Transition.java:1965)
System.err: at androidx.transition.Transition$3.onAnimationEnd(Transition.java:1914)
System.err: at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:554)
System.err: at android.animation.AnimatorSet.endAnimation(AnimatorSet.java:1301)
System.err: at android.animation.AnimatorSet.doAnimationFrame(AnimatorSet.java:1086)
System.err: at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
System.err: at android.animation.AnimationHandler.access$100(AnimationHandler.java:37)
System.err: at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
System.err: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:964)
System.err: at android.view.Choreographer.doCallbacks(Choreographer.java:790)
System.err: at android.view.Choreographer.doFrame(Choreographer.java:721)
System.err: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
System.err: at android.os.Handler.handleCallback(Handler.java:883)
System.err: at android.os.Handler.dispatchMessage(Handler.java:100)
System.err: at android.os.Looper.loop(Looper.java:214)
System.err: at android.app.ActivityThread.main(ActivityThread.java:7356)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
```
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con libnavigation-ui/src/main/java/com/mapbox/navigation/ui/RecenterButton.java, especialmente con onDetachedFromWindow y clearListeners, y revisa el stack trace proporcionado. Reproduce el fallo cambiando desde la aplicación de navegación de ejemplo y, después, verifica que separar y volver a adjuntar la vista ya no provoque el fallo por un objeto nulo.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- android, kotlin
- Área
- mobile
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 45/100