2010-05-12 70 views
1

我試圖運行Android MapView示例,並且在Eclipse中得到'無法從視圖轉換爲MapView'錯誤。Android:無法從視圖投射到MapView

我的佈局如下

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/mainlayout" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<com.google.android.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:clickable="true" 
    android:apiKey="0jwi0saLYCPGfO-t7glg5bQoBz7jVKWCcgyQWQA" 
/> 

<LinearLayout 
    android:id="@+id/zoomview" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@id/mapview" 
    android:layout_centerHorizontal="true" 
/> 

</RelativeLayout> 

和活動代碼

package org.gaz.mapapp; 

import android.os.Bundle; 
import android.view.View; 
import android.widget.LinearLayout; 
import android.widget.ZoomControls; 

import com.google.android.maps.*; 

public class MapView extends MapActivity { 

LinearLayout linearLayout; 
MapView mapView; 
ZoomControls mZoom; 

public void onCreate(Bundle savedInstance) { 
    linearLayout = (LinearLayout) findViewById(R.id.mainlayout); 
    mapView = (MapView) findViewById(R.id.mapview); 
    mZoom = (ZoomControls) mapView.getZoomControls();  
} 

@Override 
protected boolean isRouteDisplayed() { 
    // TODO Auto-generated method stub 
    return false; 
} 
} 

錯誤是由線路引起的

mapView = (MapView) findViewById(R.id.mapview); 

任何人能提供的建議,以一固定?

乾杯, Gaz。

回答

8

這可能源於你命名你自己的類MapView。嘗試指定完整的類com.google.android.maps.MapView以區別於您自己的org.gaz.mapapp.MapView

+0

我不敢相信我忽略了這一點!謝謝弗蘭克! – Gaz 2010-05-12 09:48:06

相關問題