0
我在哪裏我使用貼圖的Android應用程序工作的抱怨,這是我得到的GoogleMap的是一個空對象引用
Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.setMapType(int)' on a null object reference
此前張貼在這裏我的查詢我已經看過其他類似的錯誤問題,但我的代碼已經有所有建議,所以我希望如果有人能指出這個錯誤。
這是引發錯誤的行(第二行)。 我不知道爲什麼它是caling地圖空當我指定它(至少我覺得我有)
private void initViews() {
map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();
//map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
而且這是我的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"
android:paddingTop="65dp" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>