2016-07-25 74 views
0

我對API 10以下錯誤:GoogleMap的V2 API 10錯誤充氣類片段

FATAL EXCEPTION: main 
                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ter.androidapp/com.ter.androidapp.activities.RootActivity}: android.view.InflateException: Binary XML file line #106: Error inflating class fragment 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
                     at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
                     at android.os.Handler.dispatchMessage(Handler.java:99) 
                     at android.os.Looper.loop(Looper.java:130) 
                     at android.app.ActivityThread.main(ActivityThread.java:3683) 
                     at java.lang.reflect.Method.invokeNative(Native Method) 
                     at java.lang.reflect.Method.invoke(Method.java:507) 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
                     at dalvik.system.NativeStart.main(Native Method) 
                    Caused by: android.view.InflateException: Binary XML file line #106: Error inflating class fragment 

這是我加載地圖:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    if (mMapViewContainer == null) { 
     here it crash -> mMapViewContainer = getLayoutInflater().inflate(R.layout.fragment_geoloc_map, null); 
     mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview_geolo); 
     mapFragment.getMapAsync(this); 
    } 

    FaceBookShareManager.getInstance().initialize(getString(R.string.facebookId)); 

    getSupportFragmentManager().addOnBackStackChangedListener(this); 

    if (savedInstanceState == null) { 
     setupTabBarColors(0); 
     getSupportFragmentManager().beginTransaction().add(R.id.leftPanelContainer, new StationsSearchFragment(), Constants.TAG_STATION_FRAGMENT).commit(); 
    } 

    if (getIntent() != null && Constants.WIDGET_STATION_CLICK.equals(getIntent().getAction()) && getIntent().getData() != null) { 
     displayStationFromWidget(Integer.valueOf(getIntent().getData().getSchemeSpecificPart())); 
    } 

    setTrackFromNotif(); 

    checkForTrainFromWidget(getIntent()); 
    if (getIntent() != null && getIntent().getExtras() != null) { 
     onNewIntent(getIntent()); 
    } 
} 

這是從fragment_geoloc_map.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/topLayout" 
    android:background="@color/transparent" > 

    <TextView 
     android:id="@+id/textView_trainNum" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:gravity="center" 
     android:padding="5dip" 
     android:textSize="@dimen/xxLargeText" 
     android:visibility="gone" /> 

    <RelativeLayout 
     android:id="@+id/geolocInfoContainer" 
     android:layout_width="fill_parent" 
     android:paddingBottom="10dip" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/textView_title" 
      android:layout_width="fill_parent" 
      android:layout_height="60dip" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/btn_rechercher_red" 
      android:gravity="center" 
      android:paddingBottom="14dp" 
      android:paddingTop="14dp" 
      android:text="@string/selectStation" 
      android:textColor="@color/white" 
      android:textSize="@dimen/xxxLargeText" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/textView_choose_radius" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/imageView_refresh_map" 
      android:layout_alignTop="@+id/imageView_refresh_map" 
      android:layout_marginRight="10dp" 
      android:layout_toLeftOf="@+id/textView_radius" 
      android:gravity="center_vertical" 
      android:text="@string/radius" 
      android:textColor="@color/darkGrey" 
      android:textSize="@dimen/largeText" /> 

     <TextView 
      android:id="@+id/textView_radius" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/imageView_refresh_map" 
      android:layout_alignTop="@+id/imageView_refresh_map" 
      android:layout_marginRight="5dp" 
      android:layout_toLeftOf="@+id/imageView_refresh_map" 
      android:background="@color/radiusGrey" 
      android:drawableBottom="@drawable/ico_triangle_gris" 
      android:gravity="center_vertical" 
      android:paddingBottom="5dip" 
      android:paddingLeft="15dip" 
      android:paddingRight="15dip" 
      android:text="@string/initial_radius" 
      android:textColor="@color/radiusTextViewColor" 
      android:textStyle="bold" /> 

     <ImageView 
      android:id="@+id/imageView_refresh_map" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textView_title" 
      android:layout_marginRight="5dp" 
      android:layout_toLeftOf="@+id/imageView_backToList" 
      android:background="@color/red" 
      android:padding="8dip" 
      android:src="@drawable/ico_refresh" /> 

     <ImageView 
      android:id="@+id/imageView_backToList" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/textView_title" 
      android:layout_marginRight="10dip" 
      android:background="@color/red" 
      android:paddingBottom="8dip" 
      android:paddingLeft="10dip" 
      android:paddingRight="9dip" 
      android:paddingTop="8dip" 
      android:src="@drawable/ico_list_carte_red" /> 

    </RelativeLayout> 



    <fragment 
     class="com.google.android.gms.maps.SupportMapFragment" 
     android:id="@+id/mapview_geolo" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/geolocInfoContainer" /> 

</RelativeLayout> 

這是從艙單文件:

<meta-data 
    android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" /> 
<meta-data 
    android:name="com.google.android.maps.v2.API_KEY" 
    android:value="@string/mapsAPIv2" /> 

我已經測試了API 10,16,22,23。但在API 10中,我有膨脹問題。我不明白我有什麼改變

回答

0

從你分享它不會出現

fragment_geoloc_map.xml

在視圖層次的信息。

你需要做以下之一:

  • 包括在活動佈局片段xml文件
  • 附上SupportMapFragment在活動佈局
  • 提供你正在膨脹的片段父視圖xml文件插入而不是空

如果這沒有意義,可以請您在示例中(活動代碼和佈局文件)發佈更多代碼。


更新

您需要委派從活動/片段的MapView的生命週期事件。

你不能叫getMapAsync(OnMapReadyCallback)直到你已經委派:

  • onCreate(Bundle)
  • onResume()

則還必須委託:

  • onPause()
  • onDestroy()
  • onSaveInstanceState(Bundle)
  • onLowMemory()

要的MapView爲了防止內存泄漏和分配。