0

I used a sliding menu and I had a map fragment, when I clicked on the location menu for a first time it worked without problem but for a second time I get the following error:

FATAL EXCEPTION: main
                                             android.view.InflateException: Binary XML file line #34: Error inflating class fragment
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                 at mdev.com.mymemories.fragment.LocationFragment.onCreateView(LocationFragment.java:70)
                                                 at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
                                                 at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
                                                 at android.app.BackStackRecord.run(BackStackRecord.java:635)
                                                 at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
                                                 at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
                                                 at android.os.Handler.handleCallback(Handler.java:615)
                                                 at android.os.Handler.dispatchMessage(Handler.java:92)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: java.lang.IllegalArgumentException: Binary XML file line #34: Duplicate id 0x7f0d00be, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment

The XML file:

  <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@drawable/bg16">
<LinearLayout
    android:layout_marginBottom="10dp"
    android:id="@+id/ln"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <Button
        android:id="@+id/curent_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:text="@string/btnposition" />

</LinearLayout>
<fragment
    android:layout_marginTop="50dp"
    android:layout_gravity="center"
    android:layout_marginRight="5dp"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
 </RelativeLayout>

MyView.class:

public class LocationFragment extends Fragment {
View rootView;
public LocationFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     rootView = inflater.inflate(R.layout.fragment2, container, false);
 }
 }

sliding menu

marwa
  • 85
  • 3
  • 10
  • The last line of your logs looks as if you are recreating the fragment although the first on is still alive. Could that be the problem? – kalabalik Jun 16 '16 at 22:45
  • I think that's the problem, do you any solution with `onDestroyView()` ? – marwa Jun 16 '16 at 22:54
  • Let's see the code where you instantiate the fragment (in your activity probably). Could you not just reuse the same variable when you recreate the fragment? - Got to run, sorry! Hope someone else jumps in. – kalabalik Jun 16 '16 at 22:58

1 Answers1

0

consider that fragment manager don't like to hold second fragment with same id/tag :)

do you know purpose of fragment manager ?

at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)                                             
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
Community
  • 1
  • 1
ceph3us
  • 7,326
  • 3
  • 36
  • 43