android kotlin Does not display the a simple map

472
0
08-31-2021 04:18 AM
NivNaory
New Contributor

hello, I have a problem when I tried to display a map with kotlin.

I have the following code on kotlin and java

kotlin:

 

 

 

class MainActivity : AppCompatActivity() {
    private val activityMainBinding by lazy {
        ActivityMainBinding.inflate(layoutInflater)
    }
    private val mapView: MapView by lazy {
        activityMainBinding.mapView
    }
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)

           
            // create a new map with an imagery basemap and set it to the map view
            var map= ArcGISMap(Basemap.Type.STREETS,34.056295,-117.195800,17)
            mapView.map=map
        }
            override fun onPause() {
                mapView.pause()
                super.onPause()
            }

            override fun onResume() {
                super.onResume()
                mapView.resume()
            }

            override fun onDestroy() {
                mapView.dispose()
                super.onDestroy()
            }
        }

 

 

 

 

java:

 

 

 

public class MainActivity extends AppCompatActivity {
    private MapView mMapView;
    private ArcGISMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // inflate MapView from layout
        mMapView = findViewById(R.id.mapView);
        // create a map with the a topographic basemap
        map= new ArcGISMap(Basemap.Type.STREETS,34.056295,-117.195800,17);
        mMapView.setMap(map);
    }

    @Override
    protected void onPause() {
        mMapView.pause();
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.resume();
    }

    @Override
    protected void onDestroy() {
        mMapView.dispose();
        super.onDestroy();
    }
}

 

 

 

 And the problem is that in java it works perfectly and displays a map well. but in kotlin it doesn't work and show me a blank page and doesn't display a map.

and I follow the documentation step by step.

there is something I missed mabye? I open a new project with kotlin and install all the requirements for this project.

0 Kudos
0 Replies