2012-03-06 120 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