2013-11-14 3 views
1

내가 가진 조각 :SupportMapFragment 안드로이드에 NullPointerException이와 충돌 4.1

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/fragment_map_google_drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/fragments_map_google" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="ru.my_app.TransparentSupportMapFragment" /> 
</android.support.v4.widget.DrawerLayout> 

및 클래스 :

public class TransparentSupportMapFragment extends SupportMapFragment { 

public TransparentSupportMapFragment() { 
    // SupportMapFragment sp; 
    super(); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup view, Bundle savedInstance) { 

    View layout = super.onCreateView(inflater, view, savedInstance); 
    FrameLayout frameLayout = new FrameLayout(getActivity()); 
    frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent)); 
    ((ViewGroup) layout).addView(frameLayout, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
    return layout; 
} 

}

그리고에 내 내가지도 조각을하기 위해 노력하고있어 SherlockFragmentActivity :

map = ((TransparentSupportMapFragment) getSupportFragmentManager() 
       .findFragmentById((R.id.fragments_map_google))).getMap(); 

이 코드는 2.3, 4.0과 다른 divices HTS 하나의 S에서 잘 작동합니다. 그러나 삼성 갤럭시 S III (4.1.4) 또는 Sonu Xperia Z (4.1.2 map)는 null입니다.

이유를 말해 줄 수 있습니까? =/

+1

기본지도 시스템이로드되고 조각의 기본보기가있는 경우에만 getMap()을 사용하여 GoogleMap을 얻을 수 있습니다. 이 클래스는지도 시스템과 뷰를 자동으로 초기화합니다. 그러나 이는 Google Play 서비스 APK의 가용성에 달려 있기 때문에 준비가되면 보장 할 수 없습니다. GoogleMap을 사용할 수없는 경우 getMap()은 null을 반환합니다. https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/SupportMapFragment –

+0

@twntee 내 조각의 onCreate() 메소드에서 getMap()을 사용합니다. 그럼 ... 어떻게이 null 문제를 피할 수 있을까요? – Suvitruf

+0

당신의 대답은 정확하지 않지만, 내가 한 일은'Fragment' 클래스를 확장하고,'SupportMapFragment'를 내 조각 레이아웃 xml에 추가 한 다음 Fragment의 onCreateView에서 가져옵니다. –

답변

1

기기에 Google Play 서비스의 이전 버전이 있기 때문입니다. 그냥 그것을 업데이 트하고, 이제지도 잘 작동합니다.

관련 문제