Error starting Map Activity

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Error starting Map Activity

Postby Draffodx » Thu Mar 19, 2009 9:04 pm

I have an application that starts off as a menu of buttons and when one of the buttons is clicked it starts a map activity, but currently when I try to do this i get a noclassdeffounderror when I try to run the mapactivity but it runs fine if its not a mapactivity??

heres my intent

[code]case R.id.new_button:
Intent m = new Intent(this, Game.class);
startActivity(m);
break;[/code]

the mapactivity is called game

here is the code for it

[code]public class Game extends MapActivity {
private FrameLayout frame;
private MapView map;
private MapController controller;
List<Overlay> mapOverlays;
Drawable drawable;
HelloItemizedOverlay itemizedOverlay;
mapLocation maplocation;
private MapLocationOverlay overlay;
private List<mapLocation> mapLocations;
//MapLocationViewer maplocationviewer;
GeoPoint point = new GeoPoint(53984004,-6395207);
OverlayItem overlayitem = new OverlayItem(point, "", "");
private static String TREASURE_PROXIMITY_ALERT = "in the zone";
private static final String TAG = "Android Dkit";

public static final String KEY_DIFFICULTY = "difficulty";
public static final int DIFFICULTY_EASY = 0;
public static final int DIFFICULTY_MEDIUM = 1;
public static final int DIFFICULTY_HARD = 2;


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

Log.d(TAG, "onCreate");

int diff = getIntent().getIntExtra(KEY_DIFFICULTY,
DIFFICULTY_EASY);

initMapView();
initZoomControls();
initMyLocation();
// Zoom in
controller.setZoom(17);
mapOverlays = map.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.androidmarker);
itemizedOverlay = new HelloItemizedOverlay(drawable);
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);





LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);

Location location = locationManager.getLastKnownLocation(provider);

updateWithNewLocation(location);

locationManager.requestLocationUpdates(provider, 200, 5, locationListener);

setProximityAlert();

map.setClickable(true);
overlay = new MapLocationOverlay(this);
map.getOverlays().add(overlay);
map.getController().setCenter(getMapLocations().get(0).getPoint());


}

private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}

public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}

public void onProviderEnabled(String provider) {}

public void onStatusChanged(String provider, int status, Bundle extras) {}
};

/** Update the map with a new location */
private void updateWithNewLocation(Location location) {
// TextView myLocationText = (TextView)findViewById(R.id.myLocationText);

String latLongString;
String addressString = "No address found";

if (location != null) {
// Update my location marker
itemizedOverlay.setLocation(location);

// Update the map location.
Double geoLat = location.getLatitude()*1E6;
Double geoLng = location.getLongitude()*1E6;
GeoPoint point = new GeoPoint(geoLat.intValue(), geoLng.intValue());

controller.animateTo(point);

double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;

Geocoder gc = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(lat, lng, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
Address address = addresses.get(0);

for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
sb.append(address.getAddressLine(i)).append("\n");

sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
} catch (IOException e) {}
} else {
latLongString = "No location found";
}
// myLocationText.setText("Your Current Position is:\n" + latLongString + "\n" + addressString);
}

/** Find and initialise the map view. */
private void initMapView() {
frame = (FrameLayout) findViewById(R.id.frame);
map = (MapView) findViewById(R.id.map);
controller = map.getController();
map.setSatellite(true);
}



/** Get the zoom controls and add them to the bottom of the map. */
private void initZoomControls() {
View zoomControls = map.getZoomControls();
FrameLayout.LayoutParams p = new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM + Gravity.CENTER_HORIZONTAL);
frame.addView(zoomControls, p);
}



/** Start tracking the position on the map. */
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
overlay.enableCompass(); // no effect in emulator
overlay.runOnFirstFix(new Runnable() {
public void run() {
// Zoom in to current location
controller.setZoom(12);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}

/** Configure a proximity alert */
private void setProximityAlert() {
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

double lat = 53.794282;
double lng = -6.610250;
float radius = 100f; //meters
long expiration = -1; //do not expire

Intent intent = new Intent(TREASURE_PROXIMITY_ALERT);
PendingIntent proximityIntent = PendingIntent.getBroadcast(getApplicationContext(), -1, intent, 0);
locationManager.addProximityAlert(lat, lng, radius, expiration, proximityIntent);

IntentFilter filter = new IntentFilter(TREASURE_PROXIMITY_ALERT);
registerReceiver(new ProximityIntentReceiver(), filter);
}

/** Proximity Alert Broadcast Receiver */
public class ProximityIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive (Context context, Intent intent) {
String key = LocationManager.KEY_PROXIMITY_ENTERING;

Boolean entering = intent.getBooleanExtra(key, false);
Toast.makeText(Game.this, "Treasure: " + entering, Toast.LENGTH_LONG).show();
//[ ... perform proximity alert actions ... ]
}
}

public List<mapLocation> getMapLocations() {
if (mapLocations == null) {
mapLocations = new ArrayList<mapLocation>();
mapLocations.add(new mapLocation("Car Park 4, Paid Parking, Small",53.986467 ,-6.393211));
mapLocations.add(new mapLocation("Car Park 3, Paid Parking, Medium",53.986092 ,-6.394590));
mapLocations.add(new mapLocation("Car Park 2, Paid Parking, Large",53.986025,-6.395218));
mapLocations.add(new mapLocation("Car Park 1, Lecturer Parking Only",53.984483,-6.395110));
mapLocations.add(new mapLocation("Car Park 5, Lecturer Parking Only",53.983877,-6.394730));
mapLocations.add(new mapLocation("Car Park 6, Paid Parking, Large",53.982389 ,-6.392353));
mapLocations.add(new mapLocation("Car Park 8, Free Parking, Medium",53.982748 ,-6.392578));
mapLocations.add(new mapLocation("Car Park 9, Paid Parking, Small",53.982584 ,-6.391205));
}
return mapLocations;
}



@Override
protected boolean isRouteDisplayed() {
// Required by MapActivity
return false;
}
}
[/code]

apologies it is very badly written at the minute as I am only learning android, can anybody spot what might be causing the error?

My java and android are all up to date and all
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Postby Draffodx » Thu Mar 19, 2009 10:57 pm

found the error, <uses-library android:name="com.google.android.maps" /> missing from manifest! :roll:
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 6 guests