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

612
1
11-19-2021 09:26 AM
ScottBing2
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(
ArcGISVectorTiledLayer(getString(R.string.navigation_vector))
)
}

mapView.apply {
// set the map to be displayed in this view
this.map = 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
}
mapView.graphicsOverlays.add(graphicsOverlay)
}/>

Error occurs at highlighted code in red font.

  

0 Kudos
1 Reply
CodeDynode
New Contributor

Hello,

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

instead of

'this.map = map'.

I hope this will resolve you're the issue.

Thanks

0 Kudos