title: Android fragment cannot be cast to android.app.Activity
body: <p>I got an error reported from a user the other day, but how it happened is boggling my mind.</p>
  
  <pre><code>java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.inthub.greenfly/com.inthub.greenfly.view.fragment.MyProfileFragment}: java.lang.ClassCastException: com.inthub.greenfly.view.fragment.MyProfileFragment cannot be cast to android.app.Activity
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
     at android.app.ActivityThread.access$600(ActivityThread.java:141)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:5041)
     at java.lang.reflect.Method.invokeNative(Method.java)
     at java.lang.reflect.Method.invoke(Method.java:511)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
     at dalvik.system.NativeStart.main(NativeStart.java)
  Caused by: java.lang.ClassCastException: com.inthub.greenfly.view.fragment.MyProfileFragment cannot be cast to android.app.Activity
     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
     at android.app.ActivityThread.access$600(ActivityThread.java:141)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:5041)
     at java.lang.reflect.Method.invokeNative(Method.java)
     at java.lang.reflect.Method.invoke(Method.java:511)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
     at dalvik.system.NativeStart.main(NativeStart.java)
  </code></pre>
  
  <p>I know your first thought is "you must be starting up the fragment with startActivity or something". I start up this fragment in one single place:</p>
  
  <pre><code>FragmentTransaction ft = getFragmentManager().beginTransaction();
                      ft.replace(R.id.fragment, new MyProfileFragment());
                      ft.commit();
  </code></pre>
  
  <p>I have been unable to figure out how this was started as an activity and also have not been able to reproduce it. Any ideas where to continue looking?</p>
  
  <p>My class extends Fragment and not FragmentActivity.</p>
  
  <p>I have an onCreate, I've removed a little of the code to keep things short:</p>
  
  <pre><code>    @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          if (getActivity().getActionBar() != null) {
              getActivity().getActionBar().setTitle(R.string.myprofile);
          }
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, 
              ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_my_profile, container, false);
  
          .... tons of lines setting up my view ....
      }
  </code></pre>
  
  <p>I am declaring my fragments in the manifest file as activities. I am reading that it may be incorrect to do this. If that is the source of the problem why am I unable to reproduce the error across multiple devices?</p>
  
  <pre><code>&lt;activity
     android:name="com.inthub.greenfly.view.fragment.MyProfileFragment"
     android:screenOrientation="portrait" &gt;
  &lt;/activity&gt;
  </code></pre>
  
  <p>Update, just to be clear. I have had the incorrect activity lines in my manifest for quite some time and have never encountered this error. It was reported through Crashlytics from another user. I have spent hundreds of hours developing and testing across multiple devices and not encountered it. If it is as simple as removing the lines, why am I unable to reproduce it?</p>