我需要对MapView中的两个方法进行一些更改,所以我做了一个扩展它的类。当我尝试使用这个类时,应用程序崩溃并且使用Log:无法启动活动。
GameMapActivity: java.lang.ClassCastException: com.google.android.maps.MapView cannot be cast to com.lemonbyte.games.lbg.mapViewC
由于mapViewC mapView = (mapViewC) findViewById(R.id.mapview);
我的班级在下面
公共类mapViewC扩展了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);
}
}
我做错了什么? :)谢谢!
答案 0 :(得分:3)
将布局xml中的MapView
元素重命名为com.lemonbyte.games.lbg.mapViewC
(另外,作为标准,类以大写的第一个字母命名)。