2012-03-06 121 views
0

我需要对MapView中的两个方法进行一些更改,所以我做了一个扩展它的类。当我试图使用这个类的应用程序崩溃,并与日志:无法启动活动。扩展MapView

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

也显示您的layout.xml文件。 – 2012-03-06 13:13:18

回答

3

将您的布局xml中的MapView元素重命名为com.lemonbyte.games.lbg.mapViewC(同样,作为标准,类以大写首字母命名)。

+0

谢谢雅米! :) – Misca 2012-03-08 10:02:21