com.esri.arcgisruntime.mapping.view.MapView.setMap Attempt to invoke virtual method on a null object reference

11-19-2021 09:26 AM
New Contributor

I am attempting to execute thecode where the error occur Kotlin sample code for Find_Route and I get the following error at line 71 in the code:    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.esri.arcgisruntime.mapping.view.MapView.setMap(com.esri.arcgisruntime.mapping.ArcGISMap)' on a null object reference.

Here is the code where the error occurs:


// create a map with the basemap
val map = ArcGISMap().apply {
// set the basemap with the vector tiled layer from a service URL
basemap = Basemap(

mapView.apply {
// set the map to be displayed in this view = map <<<< Error occurs here...
// set initial viewpoint to San Diego
setViewpoint(Viewpoint(32.7157, -117.1611, 200000.0))
// ensure the floating action button moves to be above the attribution view
addAttributionViewLayoutChangeListener { _, _, _, _, bottom, _, _, _, oldBottom ->
val heightDelta = bottom - oldBottom
(directionFab.layoutParams as ConstraintLayout.LayoutParams).bottomMargin += heightDelta

Error occurs at highlighted code in red font.


0 Kudos
1 Reply
New Contributor


I would like to suggest you please use 
' = map'

instead of

' = map'.

I hope this will resolve you're the issue.


0 Kudos