mercredi 6 mai 2015

Android: Error inflating fragment with map in drawerlayout

I have app that has map in the second menu in drawerlayout. When i try to inflate the fragment with map the app crashes.

Following is the code:

 if (rootView != null) {
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }
    }

    try {
        rootView = inflater.inflate(R.layout.fragment_map, container, false);


    } catch (Exception e) {

        e.printStackTrace();
    }

Following is the exception generated:

android.view.InflateException: Binary XML file line #23: Error inflating class fragment

I've tried many solutions on stack and other platforms but in vain.

This is how i am using map fragment within parent RelativeLayout in my xml:

 <fragment 
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.SupportMapFragment"/>

I also tried removing the map fragment in its onDestroyView methos:

@Override
 public void onDestroyView() {

     super.onDestroyView();

     SupportMapFragment fragment = ((SupportMapFragment) getChildFragmentManager()
             .findFragmentById(R.id.map));
     try{
         if (fragment != null)
             getChildFragmentManager().beginTransaction().remove(fragment).commit();
     }catch(Exception e){
     }


 }

Aucun commentaire:

Enregistrer un commentaire