mapbox / mapbox/mapbox-navigation-android
Crash on addProgressChangeListener even if the progress listener is given.
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 651
- Forks
- 321
- PR merge metrics
- No merged PRs in 30d
Description
**Android API: Android X**
**Android Target Level: 29**
**Mapbox Navigation SDK version: 0.42.6**
### Problem description
The error occurs in a complicated structure. I have two instances of navigators in my app: one is in a portrait mode, and another is in landscape mode, and they have to be different due to the app design.
The portrait one works fine, there aren't problems.
The landscape one, instead, doesn't work. This navigationView is inflated in a fragment located in a view pager, so is one of the fragments you can swipe to.
Long story short, i'm using also the navigationView's child mapView to set markers and route to show the preview route to the user. When the user is ok with the route, he can press the start button, which makes all crash. But I cannot understand what is appening at the time this crash occurs.
### Code part
Here i will share with you some of my code to help you understand the situation.
`// creating navigation options
val options = NavigationViewOptions.builder()
.navigationListener(this)
.directionsRoute(currentRoute)
.shouldSimulateRoute(false)
.instructionListListener(this)
.routeListener(this)
.speechAnnouncementListener(this)
.bannerInstructionsListener(this)
.progressChangeListener { location, routeProgress ->
logger.debug(location.toString())
logger.debug(routeProgress.toString())
}.build()
logger.debug("Landscape navigator: assignment proof: "+(options.progressChangeListener()== null).toString())
// start navigation
navigationView.startNavigation(options)`
`
2020-10-02 15:30:53.164 12458-12458/it.dummy.mobile.application/LandscapeNavigationFragment: Landscape navigator: assignment proof: false
...
2020-10-02 15:30:53.295 12458-12458/it.dummy.mobile.application E/AndroidRuntime: FATAL EXCEPTION: main
Process :it.dummy.mobile.application, PID: 12458
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.services.android.navigation.ui.v5.map.NavigationMapboxMap.addProgressChangeListener(com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation)' on a null object reference
at com.mapbox.services.android.navigation.ui.v5.NavigationView.initializeNavigationListeners(NavigationView.java:691)
at com.mapbox.services.android.navigation.ui.v5.NavigationView.initializeNavigation(NavigationView.java:632)
at com.mapbox.services.android.navigation.ui.v5.NavigationView.startNavigation(NavigationView.java:394)
at it.dummy.mobile.application.ui.LandscapeNavigationFragment$setRouteInfoOnLayout$3.onClick(LandscapeNavigationFragment.kt:1712)
at android.view.View.performClick(View.java:7862)
at android.view.View.performClickInternal(View.java:7831)
at android.view.View.access$3600(View.java:879)
at android.view.View$PerformClick.run(View.java:29359)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)`
### Other informations
The map is used and works until the navigation is set to start. I also tried to make my fragment extend the progressChangeListener, without any different results. The code posted is one of the last tries i made. It seems that until the library goes to retrieve the listener from the NavigationViewOptions object, it loses his reference. Or maybe the NavigationView's mapView is not meant to be used outside the navigation purpose. Those are my mainly two suspects.
I hope i've been clear enought. Can someone help my sad soul?
Many thanks to whoever reply to me.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at NavigationView.startNavigation and inspect initializeNavigation and initializeNavigationListeners, especially NavigationMapboxMap.addProgressChangeListener at NavigationView.java:691. Reproduce the crash with two NavigationView instances in a ViewPager and the provided NavigationViewOptions. Done means starting navigation no longer dereferences a null NavigationMapboxMap when a progress listener is supplied.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100