this is the first question I am posting on stack overflow. So if I have made any mistakes while posting the issue please feel free to tell me. I am developing an application using Mapbox's navigation SDK. I can show the map along with a driving route from source to destination but when I tap on the start navigation button the app is crashing.
Logcat showing->
**Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.services.android.navigation.ui.v5.NavigationView.onCreate(android.os.Bundle)' on a null object reference at com.mapbox.services.android.navigation.ui.v5.MapboxNavigationActivity.onCreate(MapboxNavigationActivity.java:32)
MyCode**
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(getString(R.string.navigation_guidance_day), style -> {
enableMyLocationIfPermitted(style);
button = findViewById(R.id.startButton);
button.setOnClickListener(v -> {
boolean simulateRoute = true;
NavigationLauncherOptions options = NavigationLauncherOptions.builder()
.directionsRoute(currentRoute)
.shouldSimulateRoute(simulateRoute)
.build();
NavigationLauncher.startNavigation(this, options);
});
});
}
MapboxNavigationActivity is a predefined class of Mapbox navigation SDK. By debugging the app, I found that the navigationView object is appearing null and this is the reason for the crash. I don't have an idea why it is null.