mapbox / mapbox/mapbox-navigation-android

Crash: Attempt to invoke virtual method 'void com.mapbox.navigation.ui.MultiOnClickListener.clearListeners()' on a null object reference

Đang mở
#3,901 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Kotlin
Star
651
Fork
321
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**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)
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với libnavigation-ui/src/main/java/com/mapbox/navigation/ui/RecenterButton.java, đặc biệt là onDetachedFromWindow và clearListeners, rồi xem xét stack trace được cung cấp. Tái hiện sự cố bằng cách chuyển khỏi ứng dụng điều hướng mẫu, sau đó xác minh rằng việc tách và gắn lại view không còn gây ra sự cố do đối tượng null.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, kotlin
Lĩnh vực
mobile
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.