title: fragments class unable to start activity componentinfo
body: <p>I wanted to learn Fragment. So started to learning from <a href="http://www.tutorialspoint.com/android/android_fragments.htm" rel="nofollow">tutorialspoint.com</a>.
  The Example was:</p>
  
  <blockquote>
    <p>This example will explain you how to create your own Fragments. Here
    we will create two fragments and one of them will be used when device
    is in landscape mode and another fragment will be used in case of
    portrait mode.</p>
  </blockquote>
  
  <p>When I runned application occurred this Exception:</p>
  
  <pre><code>04-08 10:57:20.135  19408-19408/net.motameni.apps.fragments D/AndroidRuntime﹕ Shutting down VM
  04-08 10:57:20.137  19408-19408/net.motameni.apps.fragments E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: net.motameni.apps.fragments, PID: 19408
      java.lang.RuntimeException: Unable to start activity ComponentInfo{net.motameni.apps.fragments/net.motameni.apps.fragments.MainActivity}: android.view.InflateException: Binary XML file line #9: 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 #9: 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 android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
              at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
              at net.motameni.apps.fragments.MainActivity.onCreate(MainActivity.java:17)
              at android.app.Activity.performCreate(Activity.java:5933)
              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: java.lang.NullPointerException
              at java.lang.VMClassLoader.findLoadedClass(Native Method)
              at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:362)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:499)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
              at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:454)
              at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2123)
              at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297)
              at android.support.v7.app.ActionBarActivity.onCreateView(ActionBarActivity.java:547)
              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 android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
              at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
              at net.motameni.apps.fragments.MainActivity.onCreate(MainActivity.java:17)
              at android.app.Activity.performCreate(Activity.java:5933)
              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)
  04-08 12:49:45.078  26843-26843/net.motameni.apps.fragments I/art﹕ Late-enabling -Xcheck:jni
  04-08 12:49:45.445  26843-26843/net.motameni.apps.fragments D/AndroidRuntime﹕ Shutting down VM
  04-08 12:49:45.452  26843-26843/net.motameni.apps.fragments E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: net.motameni.apps.fragments, PID: 26843
      java.lang.RuntimeException: Unable to start activity ComponentInfo{net.motameni.apps.fragments/net.motameni.apps.fragments.MainActivity}: android.view.InflateException: Binary XML file line #9: 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 #9: 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 android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
              at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
              at net.motameni.apps.fragments.MainActivity.onCreate(MainActivity.java:17)
              at android.app.Activity.performCreate(Activity.java:5933)
              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: java.lang.IllegalStateException: Fragment net.motameni.apps.fragments.Raw_Fragment did not create a view.
              at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2145)
              at android.app.Activity.onCreateView(Activity.java:5282)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
              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 android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
              at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
              at net.motameni.apps.fragments.MainActivity.onCreate(MainActivity.java:17)
              at android.app.Activity.performCreate(Activity.java:5933)
              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)
  04-08 12:49:50.902  26843-26843/net.motameni.apps.fragments I/Process﹕ Sending signal. PID: 26843 SIG: 9
  04-08 13:20:18.838  30365-30365/net.motameni.apps.fragments I/art﹕ Late-enabling -Xcheck:jni
  04-08 13:20:19.081  30365-30384/net.motameni.apps.fragments D/OpenGLRenderer﹕ Render dirty regions requested: true
  04-08 13:20:19.091  30365-30365/net.motameni.apps.fragments D/Atlas﹕ Validating map...
  04-08 13:20:19.138  30365-30384/net.motameni.apps.fragments I/Adreno-EGL﹕ &lt;qeglDrvAPI_eglInitialize:410&gt;: QUALCOMM Build: 10/28/14, c33033c, Ia6306ec328
  04-08 13:20:19.139  30365-30384/net.motameni.apps.fragments I/OpenGLRenderer﹕ Initialized EGL, version 1.4
  04-08 13:20:19.159  30365-30384/net.motameni.apps.fragments D/OpenGLRenderer﹕ Enabling debug mode 0
  04-08 13:20:41.066  31240-31260/net.motameni.apps.fragments D/OpenGLRenderer﹕ Render dirty regions requested: true
  04-08 13:20:41.072  31240-31240/net.motameni.apps.fragments D/Atlas﹕ Validating map...
  04-08 13:20:41.114  31240-31260/net.motameni.apps.fragments I/Adreno-EGL﹕ &lt;qeglDrvAPI_eglInitialize:410&gt;: QUALCOMM Build: 10/28/14, c33033c, Ia6306ec328
  04-08 13:20:41.115  31240-31260/net.motameni.apps.fragments I/OpenGLRenderer﹕ Initialized EGL, version 1.4
  04-08 13:20:41.135  31240-31260/net.motameni.apps.fragments D/OpenGLRenderer﹕ Enabling debug mode 0
  04-08 13:21:02.984  32157-32207/net.motameni.apps.fragments D/OpenGLRenderer﹕ Render dirty regions requested: true
  04-08 13:21:02.992  32157-32157/net.motameni.apps.fragments D/Atlas﹕ Validating map...
  04-08 13:21:03.031  32157-32207/net.motameni.apps.fragments I/Adreno-EGL﹕ &lt;qeglDrvAPI_eglInitialize:410&gt;: QUALCOMM Build: 10/28/14, c33033c, Ia6306ec328
  04-08 13:21:03.032  32157-32207/net.motameni.apps.fragments I/OpenGLRenderer﹕ Initialized EGL, version 1.4
  04-08 13:21:03.053  32157-32207/net.motameni.apps.fragments D/OpenGLRenderer﹕ Enabling debug mode 0
  </code></pre>
  
  <p>Why?????
  I think this is may related to API level (My application API level is 21).
  Please see example link and help. Thanks.</p>
  
  <p><strong>MainActivity.java</strong>:</p>
  
  <pre><code>package net.motameni.apps.fragments;
  
  import android.app.FragmentManager;
  import android.app.FragmentTransaction;
  import android.content.res.Configuration;
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  
  
  public class MainActivity extends ActionBarActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Configuration config = getResources().getConfiguration();
  
          FragmentManager fragmentManager = getFragmentManager();
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  
          /**
           * Check the device orientation and act accordingly
           */
          if(config.orientation == Configuration.ORIENTATION_LANDSCAPE){
              //Landscape mode of the device
              LM_Fragment lm_fragment = new LM_Fragment();
              fragmentTransaction.replace(android.R.id.content,lm_fragment);
          }else{
              //Portrait mode of the device
              PM_Fragment pm_fragment = new PM_Fragment();
              fragmentTransaction.replace(android.R.id.content,pm_fragment);
          }
          fragmentTransaction.commit();
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:baselineAligned="false"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="horizontal"&gt;
  
      &lt;fragment
          android:name="net.motameni.apps.fragments"
          android:id="@+id/lm_fragment"
          android:layout_weight="1"
          android:layout_width="0dp"
          android:layout_height="match_parent"/&gt;
  
      &lt;fragment
          android:name="net.motameni.apps.fragments"
          android:id="@+id/pm_fragment"
          android:layout_weight="2"
          android:layout_width="0dp"
          android:layout_height="match_parent"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>lm_fragment.xml</strong> (same as pm_fragment.xml):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:text="landscape"
          android:gravity="center"
          android:textColor="#000000"
          android:textSize="20sp" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>LM_Fragment.java</strong> (same as RM_Fragment):</p>
  
  <pre><code>package net.motameni.apps.fragments;
  
  import android.app.Fragment;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class LM_Fragment extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          /**
           * Inflate the layout for this fragment
           */
          return inflater.inflate(R.layout.lm_fragment,container,false);
      }
  }
  </code></pre>