У меня есть странная проблема с MapView.
<?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);
return 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(layout)
перед findViewById
?
Затем попробуйте очистить и перестроить проект. Иногда необходимо перестроить R
Это случается со мной время от времени.