1

I'm using map in fragment. First time its loading well but when I call it second getting error -

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

xml code -

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/mapfragment"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:layout_alignParentTop="true"
        android:layout_gravity="center_horizontal"
        class="com.google.android.gms.maps.SupportMapFragment" />

    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mapfragment"
         />
</RelativeLayout>

java code -

   map = ((SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.mapfragment)).getMap();

referred many questions on stack tried below code also but not working -

public void onDestroyView() {
        super.onDestroyView(); 
        Fragment fragment = (getFragmentManager().findFragmentById(R.id.mapfragment));   
        android.support.v4.app.FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
        ft.remove(fragment);
        ft.commit();
    }

Using temporary Solutions -

I'm restarting fragment activity by passing map fragment integer value so that after opening fragment activity it will load map fragment directly.

yuva ツ
  • 3,707
  • 9
  • 50
  • 78
  • What doing in the second time? please post second time related code. – Naruto Uzumaki Sep 06 '14 at 10:38
  • The posted code is related only.i'm doing this all in fragment.1st time i opened map fragment..then after another fragment when i'm trying to open map fragment getting this error – yuva ツ Sep 06 '14 at 10:42
  • Have you seen these answers??? [**Here**](http://stackoverflow.com/a/14690441/3884250) and [**Here - Preffered Solution**](http://stackoverflow.com/a/17560504/3884250) – Nadeem Iqbal Sep 06 '14 at 10:44
  • @NadeemIqbal is i have already mention it that i have referred many questions on stack. Please read my question again. I have done that part – yuva ツ Sep 06 '14 at 10:44
  • 1
    I got this error too. I could fix it only instantiating the Fragment each time it was replaced. None of solutions that I found in SO didn't work to me. – Víctor Albertos Sep 06 '14 at 10:45
  • @Override public void onDestroyView() { super.onDestroyView(); locationManager.removeUpdates(this); android.app.Fragment fragment = getActivity().getFragmentManager() .findFragmentById(R.id.map); if (null != fragment) { android.app.FragmentTransaction ft = getActivity() .getFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); } } – Hitesh Sahu Dec 18 '15 at 02:51

1 Answers1

0

Change to this:

<fragment
    android:id="@+id/mapfragment"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
     />

Refer this link for Duplicate id. it contains same error that you are getting and it worked for me ,Just use android:name attribute instead of class attriute.

Community
  • 1
  • 1
Kishan Dhamat
  • 3,746
  • 2
  • 26
  • 36