Aisha
Aisha

Reputation: 31

Android "could not find class" error

I am new to Android programming and working on a project in Eclipse.I tried the first tutorial'HelloWorld',and got this error:

Could not find class 'com.esri.android.map.MapView', referenced from method com.esri.arcgis.android.samples.helloworld.HelloWorldActivity.onCreate 

Does there have to be a layout named MapView? If so, I do not have in my project. Could you please tell me how can I get it into the project?

I also have all source folders in the project. Even mapview, don't know why it's showing this kind of error. I need help with this project and I need to complete it within a few days, but I'm stuck due to this error and can't proceed. I'm facing this same problem in all my projects, even though every one of them I tried is a sample provided by ArcGIS.

Here is the code:

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 map = null;

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

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

}

protected void onPause() {
    super.onPause();
    map.pause();
}

protected void onResume() {
    super.onResume();
    map.unpause();
}

}

Upvotes: 2

Views: 3295

Answers (5)

Stephen Quan
Stephen Quan

Reputation: 26289

The following pertains to ArcGIS Runtime SDK for Android 1.1.1 but may also apply to other versions of the ArcGIS Runtime SDK:

  1. Right click on your HelloWorld project and select Properties
  2. Select Java Build Path
  3. On the Java Build Page, Select Libaries tab
  4. Ensure ArcGIS for Android library is present
  5. If not, select "Add Library" and select "ArcGIS for Android Library Container"
  6. Also on the Java Build Page, select Order and Export tab
  7. Ensure that the "ArcGIS for Android" class is CHECKED!! <-- this could be your issue

Upvotes: 2

Nate
Nate

Reputation: 401

I had a similar issue with the sample. I had to re-add the ArcGIS library to the project several times because Eclipse kept dropping it or it would be classified as a persisted container when the project loaded.

If it was listed as a persisted container I first removed it from the build path

Then to fix it I did the following: right-clicked on the project name in the PackageExplorer -> click build path -> add libraries -> select the ArcGIS library and click next

Hope this helps.

Upvotes: 1

Mehul Joisar
Mehul Joisar

Reputation: 15358

i am also a newbie overhere so i am not pretty sure but i think HelloWorldActivity should extend MapActivity instead of Activity.

Upvotes: 0

mobile app Beginner
mobile app Beginner

Reputation: 1661

I think you may take a look:
Arcgis API for Android

Upvotes: 0

John Ericksen
John Ericksen

Reputation: 11113

It sounds like you have not imported the MapView properly, verify you have this import in the HelloWorldActivity.java:

import com.google.android.maps.MapView;

And looking at the Hello mapview tutorial it looks like they dont mention this.

In eclipse you can hit Ctrl+Shift+O to update your missing imports.

Upvotes: 0

Related Questions