title: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
body: <p>I have an activity which has 2 buttons. The fragment in my activity would change on button click. But I am facing issue as -- <code>android.view.InflateException: Binary XML file line #24: Error inflating class fragment</code> .
  Below is my code-</p>
  
  <h2><code>activity_main.xml</code></h2>
  
  <pre><code>    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity"&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:onClick="selectFrag"
          android:text="Select Fragment 1" /&gt;
  
      &lt;Button
          android:id="@+id/button2"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:onClick="selectFrag"
          android:text="Select Fragment 2" /&gt;
  
      &lt;fragment
          android:id="@+id/fragment_place"
          android:name="com.example.rahul.fragmentdemo.FragmentOne"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:layout="@layout/fragment_one" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <h2><code>MainActivity.java</code></h2>
  
  <pre><code>package com.example.rahul.fragmentdemo;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  
  public class MainActivity extends FragmentActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      public void selectFrag(View view) {
          Fragment fr = null;
  
          if (view == findViewById(R.id.button2)) {
              fr = new FragmentTwo();
  
          } else {
              fr = new FragmentOne();
          }
  
          FragmentManager fm = getSupportFragmentManager();
          FragmentTransaction fragmentTransaction = fm.beginTransaction();
          fragmentTransaction.replace(R.id.fragment_place, fr);
          fragmentTransaction.commit();
      }
  }
  </code></pre>
  
  <h2><code>FragmentOne.java</code></h2>
  
  <pre><code>package com.example.rahul.fragmentdemo;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class FragmentOne extends Fragment {
      public FragmentOne() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          Log.i("Fragment Demo", "Fragment_One onCreate()");
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_one, container, false);
  
          return view;
      }
  }
  </code></pre>
  
  <h2><code>fragment_one.xml</code></h2>
  
  <pre><code>    &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent" tools:context="com.example.rahul.fragmentdemo.FragmentOne"&gt;
  
      &lt;!-- TODO: Update blank fragment layout --&gt;
      &lt;TextView
          android:id="@+id/tvFragment_1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:text="This is Fragment 1" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>similar to <code>FragmentOne.java</code> and <code>fragment_two.xml</code>, my code has <code>FragmentTwo.java</code> and <code>fragment_two.xml</code> respectively.</p>
  
  <p>I get exception as--</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.rahul.fragmentdemo/com.example.rahul.fragmentdemo.MainActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
          at android.app.ActivityThread.access$800(ActivityThread.java:144)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5221)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
   Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
          at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
          at android.app.Activity.setContentView(Activity.java:2144)
          at com.example.rahul.fragmentdemo.MainActivity.onCreate(MainActivity.java:18)
          at android.app.Activity.performCreate(Activity.java:5937)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
   Caused by: android.support.v4.app.SuperNotCalledException: Fragment FragmentOne{3fdec5ae #0 id=0x7f0c0051} did not call through to super.onCreate()
          at android.support.v4.app.Fragment.performCreate(Fragment.java:1768)
          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:917)
          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
          at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
          at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
          at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
              at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
              at android.app.Activity.setContentView(Activity.java:2144)
              at com.example.rahul.fragmentdemo.MainActivity.onCreate(MainActivity.java:18)
              at android.app.Activity.performCreate(Activity.java:5937)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>
  
  <p>-- where <code>MainActivity.java:18</code> refers to </p>
  
  <pre><code> setContentView(R.layout.activity_main);
  </code></pre>