Android: Cant replace fragment inside activity with another fragment?
<p>I'm new to android development and having some issues with replacing a fragment with another fragment.</p>

<p>In my <code>MainFragment.java</code>, the first thing I do in <code>onCreate</code> is check for internet connectivity, and if there is not, I replace that fragment with the <code>InternetCheckFragment</code>. However, in <code>InternetCheckFragment.java</code>, when I try to inflate my <code>check_internet.xml</code>, the app closes, but there is no error.</p>

<p>activity_main.xml:</p>



<pre><code>&lt;fragment 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:id="@+id/main_browse_fragment"
    android:name="com.ui.MainFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ui.MainActivity"
    tools:deviceIds="tv"
    tools:ignore="MergeRootFrame" /&gt;
</code></pre>

<p>MainActivity.java:</p>

<pre><code>public class MainActivity extends Activity
{
    @Override

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
</code></pre>

<p>MainFragment.java:</p>

<pre><code>public class MainFragment extends VerticalGridFragment
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        if (isConnectedToInternet() == true)
        {
            // DO stuff
        }
        else
        {
            showInternetError();
        }
    }

    public void showInternetError()
    {
        getFragmentManager().beginTransaction().replace(R.id.show_internet_error , new InternetCheckFragment())
                .commit();
    }

    ....
}
</code></pre>

<p>InternetCheckFragment.java:</p>

<pre><code>public class InternetCheckFragment extends Fragment
{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
        // Defines the xml file for the fragment
        return inflater.inflate(R.layout.check_internet, parent, false);
    }
}
</code></pre>

<p>check_internet.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/show_internet_error"
    android:background="@color/black_transparent"&gt;

    &lt;Button android:id="@+id/btn_retry"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="RETRY"
        android:layout_centerInParent="true"/&gt;

&lt;/RelativeLayout&gt;
</code></pre>

<p>However, I'm getting the error <code>No view found for id</code>.</p>

<p>I'm sure I'm not setting something correctly? Can someone point me in the right direction?</p>

<p>Thanks!</p>