I am getting a "java.lang.IllegalArgumentException: Binary XML file line #3: Duplicate id 0x7f05003f, tag null, or parent id 0x0 with another fragment" errror when I try to add a new Fragment in my main ActionBarActivity.
The main error is a android.view.InflateException: Binary XML file line #3: Error inflating class fragment error, on the return line in my PlaceDetailsFragment class.
Goal: To get a second Fragment on top the first SupportMapFragment, covering it for about 30%.
main.java
public class Main extends ActionBarActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (findViewById(R.id.fragment_container) != null) {
if (savedInstanceState != null) {
return;
}
FragmentTransaction mTransaction = getSupportFragmentManager()
.beginTransaction();
SupportMapFragment mapFragmentSupportClass = new MapFragmentClass();
mTransaction.add(R.id.fragment_container, mapFragmentSupportClass);
mTransaction.commit();
FragmentTransaction xTransaction = getSupportFragmentManager().beginTransaction();
PlaceDetailsFragment placeDetailsFragment = new PlaceDetailsFragment();
xTransaction.add(R.id.fragment_container, placeDetailsFragment);
xTransaction.commit();
}
}
PlaceDetailsFragment.java This is where the app crashes, on the return line.
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class PlaceDetailsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.details, container, false);
}
}
main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
mapfragment.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"
/>
details.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/details"
android:name="com.qstudios.whatsopenlate.PlaceDetailsFragment"
android:tag="detailsTag"
/>
To the best of my knowledge, I'm not using duplicate id's nor tags, so that leaves the parent id the fragment is sharing with mapFragment, main's fragment_container. Why is this a problem. Isn't it logical a parent has the same ID? Also, this is not a NestedFragment, correct? I'm using an ActionBarActivity and a FrameLayout to put the fragments in.
This error has halted my productivity with 2 hours already, and all of the answers I found on google were either about ActionBarSherlock, Nested Fragments, etc. None could provide a simple explanation or example on how to appropriately put 2 fragments in a FrameLayout. Even https://developer.android.com/training/basics/fragments/fragment-ui.html doesn't explain how to do this.
Anybody any experience with this, and knows what I'm doing wrong and how I could fix it?
Thanks in advance!