为什么我总是(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