我需要对MapView中的两个方法进行一些更改,所以我创建了一个扩展它的类。当我尝试使用这个类时,应用程序崩溃,并显示日志: Unable to start activity。
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);
}}
我做错了什么?:)谢谢!
发布于 2012-03-06 21:23:17
将布局xml中的MapView元素重命名为com.lemonbyte.games.lbg.mapViewC (作为标准,类的命名也是以大写首字母命名的)。
https://stackoverflow.com/questions/9584122
复制相似问题