Should i declare the MainFragmentDemoActivity in manifest?

后端 未结 3 515
别那么骄傲
别那么骄傲 2021-01-28 10:34

I am trying to learn fragment.I am clicking a fragment class and my app crashes.I have declared it in the manifest..But why it is happening..My Menu class

public         


        
3条回答
  •  执念已碎
    2021-01-28 11:10

    I think the problem is that you're Activity(Main Activity/ Activity that hosts the Fragments) doesn't extend the FragmentActivity class.

    If you're using the Support Library for ActionBar, the just make sure your Activity class extends the ActionBarActivity class.

    That's why your Fragments can't be cast into the Main Activity.(ClassCastException)

    So it should be:

    public class MainFragmentDemoActivity extends FragmentActivity .... {
    

    or:

    public class MainFragmentDemoActivity extends ActionBarActivity .... {
    

    Open for correction, as always! Regards, Edward Quixote.

提交回复
热议问题