title: Action Bar Tab must have a Callback
body: <p>I'm trying to implement an ActionBar in my application. My code is fine but when I try to load the project it gives me this error :</p>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalStateException: Action Bar Tab must have a
    Callback, and forces closure</p>
  </blockquote>
  
  <p>How can I implement a call back?</p>
  
  <pre><code>import android.app.ActionBar;
  import android.app.ActionBar.Tab;
  import android.app.Activity;
  import android.app.Fragment;
  import android.app.FragmentTransaction;
  import android.os.Bundle;
  
  public class MainResource extends Activity {
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          final ActionBar actionBar = getActionBar();
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
          Tab tabA = actionBar.newTab();
          tabA.setText("Tab A");
          tabA.setTabListener(new TabListener&lt;Categories&gt;(this, "Tag A", Categories.class));
          actionBar.addTab(tabA);
  
          Tab tabB = actionBar.newTab();
          tabB.setText("Tab B");
          tabB.setTabListener(new TabListener&lt;Favourites&gt;(this, "Tag B", Favourites.class));
          actionBar.addTab(tabB);
  
          Tab tabC = actionBar.newTab();
          tabC.setText("Tab C");
          tabC.setTabListener(new TabListener&lt;ThisWeek&gt;(this, "Tag C", ThisWeek.class));
          actionBar.addTab(tabC);
  
          Tab tabD = actionBar.newTab();
          tabC.setText("Tab D");
          tabC.setTabListener(new TabListener&lt;Estore&gt;(this, "Tag D", Estore.class));
          actionBar.addTab(tabD);
  
  
          if (savedInstanceState != null) {
              int savedIndex = savedInstanceState.getInt("SAVED_INDEX");
              getActionBar().setSelectedNavigationItem(savedIndex);
          }
      }
  
      @Override
      protected void onSaveInstanceState(Bundle outState) {
          // TODO Auto-generated method stub
          super.onSaveInstanceState(outState);
          outState.putInt("SAVED_INDEX", getActionBar().getSelectedNavigationIndex());
      }
  
  
      public static class TabListener&lt;T extends Fragment&gt; implements ActionBar.TabListener{
          private final Activity myActivity;
          private final String myTag;
          private final Class&lt;T&gt; myClass;
  
  
          public TabListener(Activity activity, String tag, Class&lt;T&gt; cls) {
              myActivity = activity;
              myTag = tag;
              myClass = cls;
          }
  
          @Override
          public void onTabSelected(Tab tab, FragmentTransaction ft) {
  
              Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
  
             // Check if the fragment is already initialized
             if (myFragment == null) {
                 // If not, instantiate and add it to the activity
                 myFragment = Fragment.instantiate(myActivity, myClass.getName());
                 ft.add(android.R.id.content, myFragment, myTag);
             } else {
                 // If it exists, simply attach it in order to show it
                 ft.attach(myFragment);
             }
          }
  
          @Override
          public void onTabUnselected(Tab tab, FragmentTransaction ft) {
              Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
              if (myFragment != null) {
                  // Detach the fragment, because another one is being attached
              ft.detach(myFragment);
              }
          }
  
          @Override
          public void onTabReselected(Tab tab, FragmentTransaction ft) {
              // TODO Auto-generated method stub
          }
      }
  }
  </code></pre>