title: Can't instantiate class.Tabs; no empty constructor, actionBar.Tab's in Android
body: <p>I have implemented a FragmentTabHost for a new tab-system. But soon realized I aswell need actionBars and tabListener support. My problem is the following: I have managed the implementation for FragmentTabHost without <strong>actionBar</strong> and <strong>tabListener</strong>(see code further below). But with FragmentActivity(using actionBars / implementing tabListener) I am not able to get the code working. What am I missing …?</p>
  
  <p><strong><em>The code I am trying with:</em></strong></p>
  
  <pre><code>import android.app.ActionBar.Tab;
  import android.app.ActionBar;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentTransaction;
  import android.widget.Toast;
  
  
  public class Tabs extends FragmentActivity {
  
      protected static final String TAG = Tabs.class.toString();
  
      private boolean haveShownStartDialog = false;
  
      protected ISettingsDataProvider settings;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          final ActionBar bar = getActionBar();
          bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
          bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
  
          bar.addTab(bar.newTab()
                  .setText("Search")
                  .setTabListener(new TabListener&lt;LandingSearch&gt;(
                          this, "search", LandingSearch.class)));
  
          bar.addTab(bar.newTab()
                  .setText("Bookmark")
                  .setTabListener(new TabListener&lt;LandingBookmark&gt;(
                          this, "bookmark", LandingBookmark.class)));
  
          bar.addTab(bar.newTab()
                  .setText("History")
                  .setTabListener(new TabListener&lt;LandingHistory&gt;(
                          this, "search", LandingHistory.class)));
  
          bar.addTab(bar.newTab()
                  .setText("Forum")
                  .setTabListener(new TabListener&lt;LandingForum&gt;(
                          this, "search", LandingForum.class)));
      }
  
  
      public static class TabListener&lt;T extends Fragment&gt; implements ActionBar.TabListener {
          private final FragmentActivity mActivity;
          private final String mTag;
          private final Class&lt;T&gt; mClass;
          private final Bundle mArgs;
          private Fragment mFragment;
          public TabListener(FragmentActivity activity, String tag, Class&lt;T&gt; clz) {
              this(activity, tag, clz, null);
          }
  
  
          public TabListener(FragmentActivity activity, String tag, Class&lt;T&gt; clz, Bundle args) {
              mActivity = activity;
              mTag = tag;
              mClass = clz;
              mArgs = args;
              // Check to see if we already have a fragment for this tab, probably
              // from a previously saved state.  If so, deactivate it, because our
              // initial state is that a tab isn't shown.
              mFragment = mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
              if (mFragment != null &amp;&amp; !mFragment.isDetached()) {
                  FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
                  ft.detach(mFragment);
                  ft.commit();
              }
          }
  
          public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) {
              // Since ActionBar.TabListener needs android.app.FragmentTransaction, define the method signature with it, but don't use it
              // Instead use the support fragment manager
              FragmentTransaction fft = mActivity.getSupportFragmentManager().beginTransaction();
  
              if (mFragment == null) {
                  mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
                  fft.add(android.R.id.content, mFragment, mTag);
              } else {
                  fft.attach(mFragment);
              }
  
              // Don't forget to call commit, as we are not using FragmentTransaction passed by ActionBar.
              fft.commit();
          }
  
          public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {
              FragmentTransaction fft = mActivity.getSupportFragmentManager().beginTransaction();
  
              if (mFragment != null) {
                  fft.detach(mFragment);
              }
  
              fft.commit();
          }
  
          public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {
              Toast.makeText(mActivity, "Reselected!", Toast.LENGTH_SHORT).show();
              }
          }
  
      }
  </code></pre>
  
  <p><strong>Example of one tab-class..</strong></p>
  
  <pre><code>public class LandingSearch extends Fragment
  {
      protected static final String TAG = LandingSearch.class.toString();
  
      …….
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View v = inflater.inflate(R.layout.landing_search, container, false);
          super.onCreateView(inflater, container, savedInstanceState, v);
          setHasOptionsMenu(true);
  
          initList(v);
  code continues….
  </code></pre>
  
  <p><strong>The new null pointer error:</strong></p>
  
  <pre><code>05-13 11:57:41.322: E/AndroidRuntime(18118): FATAL EXCEPTION: main
  05-13 11:57:41.322: E/AndroidRuntime(18118): java.lang.RuntimeException: Unable to start activity ComponentInfo{com./com.Tabs}: java.lang.NullPointerException
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.os.Handler.dispatchMessage(Handler.java:99)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.os.Looper.loop(Looper.java:137)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.app.ActivityThread.main(ActivityThread.java:4745)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at java.lang.reflect.Method.invokeNative(Native Method)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at java.lang.reflect.Method.invoke(Method.java:511)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at dalvik.system.NativeStart.main(Native Method)
  05-13 11:57:41.322: E/AndroidRuntime(18118): Caused by: java.lang.NullPointerException
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at com.Tabs.onCreate(Tabs.java:42)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.app.Activity.performCreate(Activity.java:5008)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
  05-13 11:57:41.322: E/AndroidRuntime(18118):    ... 11 more
  </code></pre>