我有一些奇怪的問題,與MapView。findViewById返回null從佈局查看
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="my-api-key"/>
而mapView = (MapView)findViewById(R.id.mapview);
對我而言返回null。但MapView顯示正常。我做錯了什麼?
UPD:有我的課
public class WayMapActivity extends MapActivity {
private MapView mapView = null;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setContentView(R.layout.maplayout);
mapView = (MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
@Override
public void onResume(){
super.onResume();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
調用*後的setContentView該行*()? – Blundell
有時候通過清理項目 – drewi
來解決。另外,你的類是否擴展了MapActivity? – drewi