title: Replacing TabActivity by Fragment : Error inflating class fragment
body: <p>I've seen that I have a common error judging by the number of similar questions asked on this forum, but I haven't found any answer in these.</p>
  
  <p>I try to use fragments in order to replace the deprecated tabActivity.</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  
  public class MediaActivity extends FragmentActivity{
  
       @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.psa_media);
          }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;fragment
          android:name="fr.partisocialite.psa.activity.TabsFragment"
          android:id="@+id/tabs_fragment"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I've also tried to replace android:name by class</p>
  
  <p>Here is my logCat :</p>
  
  <pre><code>02-09 10:07:48.738: E/AndroidRuntime(1713): FATAL EXCEPTION: main
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):
  &gt; java.lang.RuntimeException: Unable to start activity
  &gt; ComponentInfo{fr.partisocialiste.psa/fr.partisocialiste.psa.activity.MediaActivity}:
  &gt; android.view.InflateException: Binary XML file line #7: Error
  &gt; inflating class fragment 02-09 10:07:48.738: E/AndroidRuntime(1713):
  &gt;   at
  &gt; android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.app.ActivityThread.startActivityNow(ActivityThread.java:1487)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.widget.TabHost.setCurrentTab(TabHost.java:326) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:132) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:456)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.view.View.performClick(View.java:2485) 02-09 10:07:48.738:
  &gt; E/AndroidRuntime(1713):   at
  &gt; android.view.View$PerformClick.run(View.java:9080) 02-09 10:07:48.738:
  &gt; E/AndroidRuntime(1713):   at
  &gt; android.os.Handler.handleCallback(Handler.java:587) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.os.Handler.dispatchMessage(Handler.java:92) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.os.Looper.loop(Looper.java:130) 02-09 10:07:48.738:
  &gt; E/AndroidRuntime(1713):   at
  &gt; android.app.ActivityThread.main(ActivityThread.java:3683) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; java.lang.reflect.Method.invokeNative(Native Method) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; java.lang.reflect.Method.invoke(Method.java:507) 02-09 10:07:48.738:
  &gt; E/AndroidRuntime(1713):   at
  &gt; com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; dalvik.system.NativeStart.main(Native Method) 02-09 10:07:48.738:
  &gt; E/AndroidRuntime(1713): Caused by: android.view.InflateException:
  &gt; Binary XML file line #7: Error inflating class fragment 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.view.LayoutInflater.inflate(LayoutInflater.java:408) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.view.LayoutInflater.inflate(LayoutInflater.java:320) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.view.LayoutInflater.inflate(LayoutInflater.java:276) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.app.Activity.setContentView(Activity.java:1657) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; fr.partisocialiste.psa.activity.MediaActivity.onCreate(MediaActivity.java:14)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   ... 18 more 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713): Caused by:
  &gt; android.support.v4.app.Fragment$InstantiationException: Unable to
  &gt; instantiate fragment fr.partisocialite.psa.activity.TabsFragment: make
  &gt; sure class name exists, is public, and has an empty constructor that
  &gt; is public 02-09 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.support.v4.app.Fragment.instantiate(Fragment.java:332) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.support.v4.app.Fragment.instantiate(Fragment.java:300) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:248)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   ... 27 more 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713): Caused by:
  &gt; java.lang.ClassNotFoundException:
  &gt; fr.partisocialite.psa.activity.TabsFragment in loader
  &gt; dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/fr.partisocialiste.psa-1.apk]
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
  &gt; 02-09 10:07:48.738: E/AndroidRuntime(1713):   at
  &gt; java.lang.ClassLoader.loadClass(ClassLoader.java:551) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; java.lang.ClassLoader.loadClass(ClassLoader.java:511) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     at
  &gt; android.support.v4.app.Fragment.instantiate(Fragment.java:322) 02-09
  &gt; 10:07:48.738: E/AndroidRuntime(1713):     ... 30 more 02-09 10:07:48.804:
  &gt; I/global(1713): Loaded time zone names for en_US in 1110ms. 02-09
  &gt; 10:07:49.957: D/dalvikvm(1713): GC_CONCURRENT freed 908K, 51% free
  &gt; 3705K/7431K, external 2360K/3860K, paused 2ms+2ms 02-09 10:07:50.242:
  &gt; I/global(1713): Loaded time zone names for en_US in 1147ms. 02-09
  &gt; 10:07:50.410: D/dalvikvm(1713): GC_FOR_MALLOC freed 598K, 51% free
  &gt; 3698K/7431K, external 2360K/3860K, paused 38ms 02-09 10:07:50.574:
  &gt; D/dalvikvm(1713): GC_FOR_MALLOC freed 164K, 50% free 3779K/7431K,
  &gt; external 2360K/3860K, paused 51ms 02-09 10:07:50.593:
  &gt; D/dalvikvm(1713): GC_FOR_MALLOC freed 243K, 50% free 3773K/7431K,
  &gt; external 2360K/3860K, paused 15ms 02-09 10:07:50.609:
  &gt; D/dalvikvm(1713): GC_FOR_MALLOC freed &lt;1K, 47% free 4010K/7431K,
  &gt; external 2360K/3860K, paused 16ms 02-09 10:07:50.699:
  &gt; D/dalvikvm(1713): GC_CONCURRENT freed 1194K, 49% free 3982K/7687K,
  &gt; external 2360K/3860K, paused 2ms+3ms
  </code></pre>
  
  <p>Thanks a lot, I didn't succeed about making my logCat look better, sorry about that.</p>
  
  <p>Here is my class TabsFragment, </p>
  
  <p>&lt;&lt;&lt;&lt;&lt;</p>
  
  <pre><code>package fr.partisocialiste.psa.activity;
  
  import fr.partisocialiste.psa.R;
  import android.app.Activity;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TabHost;
  import android.widget.TextView;
  import android.widget.TabHost.OnTabChangeListener;
  import android.widget.TabHost.TabSpec;
  
  public class TabsFragment extends Fragment implements OnTabChangeListener{
  
      private static final String TAG = "FragmentTabs";
      public static final String TAB_HOLL = "Hollande";
      public static final String TAB_PS = "PS";
  
      private View mRoot;
      private TabHost mTabHost;
      private int mCurrentTab;
  
      public TabsFragment(){
          super();
      }
  
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          mRoot = inflater.inflate(R.layout.tabs_fragment, null);
          mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost);
          setupTabs();
          return mRoot;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          setRetainInstance(true);
  
          mTabHost.setOnTabChangedListener(this);
          mTabHost.setCurrentTab(mCurrentTab);
          // manually start loading hollande
          updateTab(TAB_HOLL, R.id.tab_hollande);
      }
  
      private void setupTabs() {
          mTabHost.setup(); // important!
          mTabHost.addTab(newTab(TAB_HOLL, R.string.tab_hollande, R.id.tab_hollande));
          mTabHost.addTab(newTab(TAB_PS, R.string.tab_ps, R.id.tab_ps));
      }
  
      private TabSpec newTab(String tag, int labelId, int tabContentId) {
          Log.d(TAG, "buildTab(): tag=" + tag);
  
          View indicator = LayoutInflater.from(getActivity()).inflate(
                  R.layout.tab,
                  (ViewGroup) mRoot.findViewById(android.R.id.tabs), false);
          ((TextView) indicator.findViewById(R.id.text)).setText(labelId);
  
          TabSpec tabSpec = mTabHost.newTabSpec(tag);
          tabSpec.setIndicator(indicator);
          tabSpec.setContent(tabContentId);
          return tabSpec;
      }
  
      @Override
      public void onTabChanged(String tabId) {
          if (TAB_HOLL.equals(tabId)) {
              updateTab(tabId, R.id.tab_hollande);
              mCurrentTab = 0;
              return;
          }
          if (TAB_PS.equals(tabId)) {
              updateTab(tabId, R.id.tab_ps);
              mCurrentTab = 1;
              return;
          }
  
      }
  
      private void updateTab(String tabId, int placeholder) {
          FragmentManager fm = getFragmentManager();
          if (fm.findFragmentByTag(tabId) == null) {
              if(TAB_HOLL.equals(tabId)){
  //              fm.beginTransaction()
  //              .replace(placeholder, new MyListFragment(tabId), tabId)
  //              .commit();
              }
              else if(TAB_PS.equals(tabId)){
  //              fm.beginTransaction()
  //              .replace(placeholder, new MyListFragment(tabId), tabId)
  //              .commit();
              }
          }
      }
  
  }
  </code></pre>