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 fragmentCaused by
java.lang.IllegalArgumentException: Binary XML file line #28: Duplicate id0x7f0d0090, tag null, or parent id0xffffffffwith another fragment forcom.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.