0

I'm making an Android application with a Google Map. I've got a problem with showing the fragment that contains the map. The first thime I've no exception but if I return to the map I've got this exception:

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

Caused by java.lang.IllegalArgumentException: Binary XML file line #28: Duplicate id 0x7f0d0090, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment.

The stacktrace you can find on Pastebin.


Here is my code on my Fragment

public class RoeteFragment extends Fragment implements OnMapReadyCallback {

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

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // exception thrown on line below
        return inflater.inflate(R.layout.fragment_roete, container, false); 
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        // not so important code for the question.
    }

    public static Fragment newInstance() {
        return new RoeteFragment();
    }
}

Here you find the xml file fragment_roete:

<?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">

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

</RelativeLayout>

Here is how I replace the old fragment with RoeteFragment:

_fragmentReplaceListener.newFragment(RoeteFragment.newInstance(_roete));

Note by code above: _fragmentReplaceListener is a declaration of an interface that is impelemented on MainActivity and contains this code:

@Override
public void newFragment(Fragment fragment) {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.frmlytContentMain, fragment);
    transaction.addToBackStack("transaction_fromOldFragment_toNewFragment");
    transaction.commit();
}

Note by code above: frmlytContentMain is a FrameLayout.

Community
  • 1
  • 1
H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144

1 Answers1

0

use MapFragment instead of SupportMapFragment

<fragment 
android:id="@+id/map"
class="com.google.android.gms.maps.MapFragment"
              android:layout_height="match_parent"
              android:layout_width="match_parent"
              />
Nitesh Pareek
  • 362
  • 2
  • 10
  • then use @Override public void newFragment(Fragment fragment) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.frmlytContentMain, fragment); transaction.addToBackStack("transaction_fromOldFragment_toNewFragment"); transaction.commit(); } – Nitesh Pareek May 13 '16 at 08:45
  • The problem is if I do this I've problems with 3 other fragments that I'll replace with the same code. So I've got [this error](http://i.stack.imgur.com/v4olo.png). Anyway, my problem is now solved by [this answer](http://stackoverflow.com/questions/14083950/duplicate-id-tag-null-or-parent-id-with-another-fragment-for-com-google-androi/14695397#14695397). Thanks for your suggestion. – H. Pauwelyn May 13 '16 at 08:55
  • 1
    OK man enjoy Keep posting questions i will be there for help :P – Nitesh Pareek May 13 '16 at 09:10