Android SDK error: Trying instantiate a class that is not a fragment

后端 未结 3 1950
日久生厌
日久生厌 2021-02-07 10:14

I am hardly trying to create a simple application with a top menu and a changeable view below (by pressing the buttons in the menu fragment we change the view of the fragment be

相关标签:
3条回答
  • 2021-02-07 10:31

    You should be using FragmentActivity instead of Activity that is because you are using support Fragments and multiple Fragments in your activity main


    Edit

    You can now use the Appcompat support library and extends AppCompatActivity to support toolbar and fragment for lower api.

    0 讨论(0)
  • 2021-02-07 10:35

    In my case it turned out, I was doing stuff in onCreate in the wrong order:

    setContentView(R.layout.activity_qr_code_scan);
    super.onCreate(savedInstanceState);
    

    instead of

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_qr_code_scan);
    
    0 讨论(0)
  • 2021-02-07 10:37

    As you are using fragments in your layout and I suggest you to extend your class from fragment or fragment activity.

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