Cannot be cast to android.app.Fragment

前端 未结 4 1384
攒了一身酷
攒了一身酷 2021-02-03 21:22

I\'m just trying to have a look on Fragment and I got some probs with stupid stuff... There is my SkippersActivity.java :

public class SkippersActivity extends A         


        
相关标签:
4条回答
  • 2021-02-03 21:41

    Another pitfall to watch out for is to make sure you don't forget to call super.onCreate() from your activity. If you make this dumb mistake like I did, you'll also see the "Error inflating class fragment" and "... cannot be cast to android.app.Fragment" errors, even if you haven't mismatched the standard and support.v4 versions of the classes.

    0 讨论(0)
  • 2021-02-03 21:48

    If I had to guess, SkippersFragment is extending android.support.v4.app.Fragment. However, SkippersActivity is not extending android.support.v4.app.FragmentActivity. So SkippersActivity is trying to use native API Level 11 fragments.

    0 讨论(0)
  • 2021-02-03 21:49

    I ran into the same error while trying to extend ListFragment. My finding is that, to use ListFragment on a project with minSdkVersion < 11, I will have to import android.support.v4.app.ListFragment;. Otherwise, I will have to import android.app.ListFragment;.

    This link clarified my question.

    0 讨论(0)
  • 2021-02-03 22:00

    If you use the v4 compatibility package, your Activity has to extend FragmentActivity, not Activity. If you use Android > 3.0, then your Activity extends Activity, but read CommonsWare's answer about not mixing both types of fragments.

    0 讨论(0)
提交回复
热议问题