I want to add button which will toggle between normal and satellite view in the map view and I keep getting a the application has stopped unexpectedly error
public class NewMapsActivity extends MapActivity
{
private MapView myMapView;
@Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
MapView myMapView = (MapView) findViewById(R.id.mapview);
Button mySatelliteButton = (Button)findViewById(R.id.c_button);
mySatelliteButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
SetSatellite();
}
});
myMapView.setBuiltInZoomControls(true);
}
private void SetSatellite()
{
if ( myMapView.isSatellite() )
myMapView.setSatellite(false);
else
myMapView.setSatellite(true);
}
@Override
protected boolean isRouteDisplayed()
{
return false;
}
}
If everything is given right then check whether nullpointer exception occur in myMapview object. since you have declared at top then inside onCreate you are using MapView mymapView=(MapView) findViewById(R.id.mapview); so when you use mymapview object inside setStallite() it will take only the object which was declare at the top. so try this
but you to declare myMapview at top as MapView myMapview;
check this if not please post your error in logcat