mapbox / mapbox/mapbox-navigation-android

Attempt to invoke virtual method 'void com.mapbox.services.android.navigation.ui.v5.MultiOnClickListener.clearListeners()' on a null object reference]

Open
#1,971 18 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug jira-sync-complete
Dominant language
Kotlin
Stars
651
Forks
321
PR merge metrics
No merged PRs in 30d

Description

Android API: 21
Mapbox Navigation SDK version: 0.39.0

Steps to trigger behavior

I'm trying to use the NavigationView on a embedded layout and trying to "move" the layout to another contentview, but it crash has soon I remove the View from the parent with:

Attempt to invoke virtual method 'void com.mapbox.services.android.navigation.ui.v5.MultiOnClickListener.clearListeners()' on a null object reference]

I have a simple class with:

public class clsNavigationView extends CoordinatorLayout implements OnNavigationReadyCallback, MapboxMap.OnMapLongClickListener,
        NavigationListener, ProgressChangeListener, InstructionListListener, SpeechAnnouncementListener,
        BannerInstructionsListener, OnTrackingModeChangedListener
...
        inflate(getContext(), R.layout.mapbox_activity_embedded_navigation, this);
...

The layout have

<com.mapbox.services.android.navigation.ui.v5.NavigationView
android:id="@+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navigationDarkTheme="@style/NavigationViewDark"
app:navigationLightTheme="@style/NavigationViewLight"/>

I put the clsNavigationView on a static FrameLayout, I add it to my mainView on another FrameLayout.

When I change view, I remove the view with:

((FrameLayout) objFrameMap.getParent()).removeView(objFrameMap);

Do my new setContentview on my main Activity.

Then I add back my Frame into my new FrameLayout on the new Content

((FrameLayout) findViewById(R.id.layer_mapview)).addView(objFrameMap);

Actual behavior

It crash at the removeView.

** I'm not using fragment.

Fix?

I tested with the source, I just add a check if multiOnClickListener before doing the clear on 3 classes (RecenterButton, FeedbackButton and SoundButton), it's seem to be fine after this change.

  private void clearListeners() {
    multiOnClickListener.clearListeners();
    multiOnClickListener = null;
    setOnClickListener(null);
  }

to

  private void clearListeners() {
    if (multiOnClickListener != null) multiOnClickListener.clearListeners();
    multiOnClickListener = null;
    setOnClickListener(null);
  }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the clearListeners methods in RecenterButton, FeedbackButton, and SoundButton, which the issue identifies as the crash sites. Reproduce the embedded NavigationView removal and reinsertion flow, then verify that removing the view no longer crashes when a listener is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.