error in my first application

2087
4
Jump to solution
12-12-2013 06:41 PM
ArowanaIndah
New Contributor III
Hi, i new in this arcgis runtime SDk for android. i have this problem where i get 'ArcGISTiledMapServiceLayer cannot be resolved to a type' and need to add 'import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;' in Activity.java to resolve the error. Here is my code. Did i do the right way?
Thank.

package com.esri.arcgis.android.samples.helloworld;

import android.app.Activity;
import android.os.Bundle;


import com.esri.android.map.MapView;
import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;


public class HelloWorldActivity extends Activity {

MapView mMapView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mMapView = new MapView(this);
// Retrieve the map and initial extent from XML layout
mMapView = (MapView)findViewById(R.id.map);
// Add dynamic layer to MapView
mMapView.addLayer(new ArcGISTiledMapServiceLayer("" +
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));

}

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

}
1 Solution

Accepted Solutions
ShellyGill1
Esri Contributor
Hi,

I'm guessing that you may have started by following this tutorial, as the names and code suggested here is consistent with your code: https://developers.arcgis.com/en/android/guide/hello-world.htm.
The "import" line that you suggested looks correct, and you should find that this runs OK and creates a simple app with a single layer of streets in it.

One difference however is that in your onCreate, the mMapView variable is set twice - first a new MapView is created in code, and then secondly a MapView is retrieved from a layout by ID.  Possibly this is just an error when you cut and pasted the code sample from the tutorial. As described in this tutorial, the simplest way to get started would be to use the second approach, where a MapView is added in the layout, and then you get a reference to the MapView from the layout by it's ID. So you can remove the line "mMapView = new MapView(this);".

View solution in original post

0 Kudos
4 Replies
ShellyGill1
Esri Contributor
Hi,

I'm guessing that you may have started by following this tutorial, as the names and code suggested here is consistent with your code: https://developers.arcgis.com/en/android/guide/hello-world.htm.
The "import" line that you suggested looks correct, and you should find that this runs OK and creates a simple app with a single layer of streets in it.

One difference however is that in your onCreate, the mMapView variable is set twice - first a new MapView is created in code, and then secondly a MapView is retrieved from a layout by ID.  Possibly this is just an error when you cut and pasted the code sample from the tutorial. As described in this tutorial, the simplest way to get started would be to use the second approach, where a MapView is added in the layout, and then you get a reference to the MapView from the layout by it's ID. So you can remove the line "mMapView = new MapView(this);".
0 Kudos
Oscar_ReneCarrillo_Garcia
New Contributor

What if I do not have the double mMapView cause I put as a comment this line //mMapView = new MapView(this);

What I am missing in the code or libraries cause I still having an error in the code

ArcGISTiledMapServiceLayer cannot be resolved to a type

0 Kudos
ShellyGill1
Esri Contributor

Hi Oscar,

If you have the correct imports statements, then it sounds likely that you don't have the Jar files in your build path that contain all the Esri classes - you can add these automatically if you have the ArcGIS Runtime SDK for Android installed in Eclipse - right-click the project and choose ArcGIS Tools -> Convert to ArcGIS Android Project. If that's option is disabled, maybe your project already had this reference but it's been broken somehow, so in that case choose Fix Project Properties instead.

The doc here will tell you more about this: Integration features—ArcGIS Runtime SDK for Android.

Hope this helps,

0 Kudos
Oscar_ReneCarrillo_Garcia
New Contributor

Thanks for your answer I though that was another thing but this could help to someone that was missing this

0 Kudos