Skip to content Skip to sidebar Skip to footer

Java.lang.classcastexception Cannot Be Cast To Android.app.fragment

I have MainActivity class which have method which instantiate ApplicationBar, all other Activities are inherited form this MainActivity so they can use this method. But I also have

Solution 1:

You are attempting to cast a SupportMapFragment to be a native API Level 11 android.app.Fragment. That will not work. Either:

  • Set your android:minSdkVersion to 11 or higher, and use MapFragment instead of SupportMapFragment, or

  • Cast your SupportMapFragment to be an android.support.v4.app.Fragment

The issue is if I extend it from FragmentActivity I cannot display ApplicationBar Tabs

The action bar was added to Android in API Level 11. If you wish to use an action bar on older versions of Android, you will need to use a backport, either ActionBarSherlock or the AppCompat backport in the Android Support package.

Solution 2:

If you are using com.google.android.gms.maps.SupportMapFragment your activity must extends android.support.v4.app.FragmentActivity instead of android.app.Activity

Post a Comment for "Java.lang.classcastexception Cannot Be Cast To Android.app.fragment"