title: FragmentActivity crashing on orientation change (MainActivity seen as Fragment)
body: <p>I am using a SherlockFragmentActivity with tabs. It loads fine the first time, but when the orientation gets changed, the following error occurs:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity  
  ComponentInfo{ext.domain.app/ext.domain.app.MainActivity}:
  android.support.v4.app.Fragment$InstantiationException: Unable to instantiate 
  fragment ext.domain.app.MainActivity$1: make sure class name exists, is public, 
  and has an empty constructor that is public
  </code></pre>
  
  <p>I've been looking at posts about similar problems, but there is a difference: in this error it seems like MainActivity is seen as a Fragment ("unable to instantiate fragment ext.domain.MainActivity"), instead of the used Fragment class being mentioned. </p>
  
  <p>It does not help to give MainActivity an empty constructor. The Fragments that I actually use are called ArticleListFragment and it is a public class with an empty constructor. </p>
  
  <p>I'm running the app on Android 2.3, below is the code (stripped of most irrelevant details and still throwing the exception):</p>
  
  
  
  <p>MainActivity.java:</p>
  
  <p><strong>(Edit: added the instantiation of the ArticleListFragment which is an anonymous inner type. It seems that if I remove it, it does work.)</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public class MainActivity extends SherlockFragmentActivity implements ActionBar.TabListener {
  
      ActionBar actionBar;
  
      public MainActivity() {
  
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.activity_main);
  
          // Create ActionBar
          actionBar = getSupportActionBar();
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
          // Create Tabs
          String[] tabs = { 
                  getString(R.string.tab1), 
                  getString(R.string.tab2), 
                  getString(R.string.tab3),
                  getString(R.string.tab4)
          };
  
          for(String tabname : tabs) {
              ActionBar.Tab tab = actionBar.newTab();
              tab.setText(tabname);
              tab.setTabListener(this);
              actionBar.addTab(tab);
          }
      }
  
      @Override
      public void onTabSelected(Tab tab, FragmentTransaction ft) {
          switch(tab.getPosition()) {
          case 0:
              ArticleListFragment home = new ArticleListFragment() { 
                              public void onAttach(Activity activity) {
                                  // This is some code to populate the Fragment with an HTTPRequest
                                  super.onAttach(activity);
                                  RequestParams paramsHome = RequestClient.getBasicRequestParams(activity);
                                  populate("frontpage", paramsHome);
                              };
                          };
              ft.replace(R.id.contentframe, home);
              break;
          case 3:
              ArticleListFragment saved = new ArticleListFragment() { 
                              public void onAttach(Activity activity) {
                                  // This is some code to populate the Fragment with an HTTPRequest
                                  super.onAttach(activity);
                                  RequestParams paramsSaved = RequestClient.getBasicRequestParams(activity);
                                  populate("saved", paramsSaved);
                              };
                          };
              ft.replace(R.id.contentframe, saved);
              break;
          }
      }
  
      @Override
      public void onTabUnselected(Tab tab, FragmentTransaction ft) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onTabReselected(Tab tab, FragmentTransaction ft) {
  
      }
  
  }
  </code></pre>
  
  <p>ArticleListFragment.java:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class ArticleListFragment extends SherlockFragment {
      public ArticleListFragment() {
  
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      public View onCreateView(final LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
          LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.fragment_articlelist, null);
          return layout;
      }
  }
  </code></pre>
  
  <p>Any ideas why this code is wrong?</p>