java.lang.IllegalArgumentException: No view found for id 0x1020002 (android:id/content) for fragment

When you use fragmentTransaction.replace(R.id.container,fragment) it will remove any fragments that are already in the container and add your new one to the same container.

Now i can suggest you 2 things.First, if you want to use fragmentTransaction.replace(android.R.id.content, fragment); which you are doing right now,then don't set content for your Activity using setContentView.This should work fine then.To know what exactly android.R.id.content is you can refer this stackoverflow question and answer

Or Secondly, In the layout of your Activity have a FrameLayout whose id is content. And then use

fragmentTransaction.replace(R.id.content, fragment);  
fragmentTransaction.addToBackStack(null);//add the transaction to the back stack so the user can navigate back
// Commit the transaction
fragmentTransaction.commit();  

Hope this helps.

More Info:

From your comments it seems that you are having some problem in getting the idea of using FrameLayout in your Activity's layout(Not of any of the Fragment's layout).From the Documents

FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.

So the main purpose of FrameLayout is to block the area required to fit the largest child view. If you use a FrameLayout as Fragment Container you can ensure that you always have the space available to accommodate the largest Fragment's layout.

So you can have your FrameLayout something like this in your Activity's layout xml file

<FrameLayout
    android:id="@+id/content"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
 <!--you can put your existing views of your current xml here, so yes your entire xml is now inside this FrameLayout -->
</FrameLayout>

I don't use getSupportFragmentManager(). I use getChildFragmentManager() and it worked for me. You can try it.


If you are trying to put Fragment into Fragment, use getChildFragmentManager()