-3

I try to install carto to Android studio but I have a lot errors. I follow the instructions of the carto web site (https://carto.com/developers/mobile-sdk/guides/getting-started/#tab-java).

package com.example.vassilis.goldman_carto;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.carto.layers.CartoBaseMapStyle;
import com.carto.layers.CartoOnlineVectorTileLayer;
import com.carto.ui.MapView;

public class MainActivity extends AppCompatActivity {

    // make sure you replace the String value with the one from carto.com mobile app registration !
    final String LICENSE = "insert license key - hello stackoverflow";

    private MapView mapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Register the license so that CARTO online services can be used
        MapView.registerLicense(LICENSE);

        // Get 'mapView' object from the application layout
        mapView = (MapView) this.findViewById(R.id.mapView);

        // Add basemap layer to mapView
        CartoOnlineVectorTileLayer baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CARTO_BASEMAP_STYLE_VOYAGER);
        mapView.getLayers().add(baseLayer);
    }

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

}

error: method registerLicense in class MapView cannot be applied to given types; required: String,Context found: String reason: actual and formal argument lists differ in length

enter image description here

Vassilis
  • 341
  • 1
  • 8
  • 22
  • 2
    it doesn't look like you have any Android experience. Don't start from real project, do some tutorials first – Vladyslav Matviienko Jan 11 '19 at 12:17
  • No I don't have, but can someone explain me why -2? – Vassilis Jan 11 '19 at 13:59
  • 1
    Just because you did no attempt to solve the problem yourself. – Vladyslav Matviienko Jan 11 '19 at 15:17
  • 2
    Please add code, errors and data as **text** ([using code formatting](//stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](https://meta.stackoverflow.com/a/285557). In general, code/errors/data in text format >>>> code/errors/data as an image >> nothing. Images should only be used, *in addition to text in code format*, if having the image adds something significant that is not conveyed by just the text code/error/data. – Makyen Jan 11 '19 at 23:36

1 Answers1

3

You have 3 errors in your console.

1st:

onCreate is already defined

You have the onCreate method twice, delete the second one.

2nd:

method registerLicense cannot be applied to given params, requires String & Context, found String

looks like MapView.registerLicense should take a string and a context, i.e. MapView.registerLicense(LICENSE, this);

3rd:

cannot find symbol variable main

Finally you are using R.layout.main when it should be R.layout.activity_main (the name of your XML layout file).


Pro Tip - anything with a red line underneath it is bad, and your app won't work/run/compile until you have fixed the errors and made the red lines disappear.

Blundell
  • 75,855
  • 30
  • 208
  • 233