I need to make some changes to two methods in MapView so I’ve done a class that extends it. When I’m trying to use this class the app crashes and with the Log: Unable to start activity.
GameMapActivity: java.lang.ClassCastException: com.google.android.maps.MapView cannot be cast to com.lemonbyte.games.lbg.mapViewC
Because of mapViewC mapView = (mapViewC) findViewById(R.id.mapview);
My class is below
public class mapViewC extends MapView{
public mapViewC(android.content.Context context, android.util.AttributeSet attrs){
super(context,attrs);
}
public mapViewC(Context context, String apiKey)
{
super(context, apiKey);
}
public mapViewC(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
@Override
public void dispatchDraw(Canvas canvas) {
//limit zoom level
if(getZoomLevel() >15){
getController().setZoom(15);
getController().setCenter(new GeoPoint(0, 0));
//dont draw as it will just be blank and then jump
return;
}
super.dispatchDraw(canvas);
}
}
What am I doing wrong? 🙂 thank you!
Rename your
MapViewelement in your layout xml ascom.lemonbyte.games.lbg.mapViewC(also, as a standard, classes are named with an upper-case first letter).