爲什麼我總是(FrameLayout)findViewById總是返回null? 該文件存在。 使用Google地圖。 我閱讀了相關的主題。 技術支持: 項目清潔。 刪除文件夾gen。(FrameLayout)findViewById - 返回null?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.travel_map_activity);
mapView = (MapView) findViewById(R.id.travelMapView);
FrameLayout mainLayout = (FrameLayout) findViewById(R.id.mapFrame);//null
}
什麼問題?
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapFrame"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/tvTop"
android:layout_width="fill_parent"
android:layout_height="20dip"
android:background="#FFFFFF"
android:gravity="top|center_horizontal"
android:text="FLOATING VIEW - TOP"
android:textColor="#000000"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/lvMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout></FrameLayout>
travel_map_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/travelMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="key" />
</LinearLayout>
感謝
那是'travel_map_activity.xml'?我覺得不行,因爲在上面的行上引用了'R.id.travelMapView'。 – Eric
travel_map_activity.xml添加後。 – JDev