The code is as follows
1 Public classMainactivityextendsfragmentactivity {2 3 @Override4 Public voidonCreate (Bundle savedinstancestate) {5 Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.activity_main);7Fragmentmanager fm=Getsupportfragmentmanager ();8Fragment fragment=Fm.findfragmentbyid (r.id.fragmentcontainer);9 if(Fragment = =NULL) {Ten fragment=new crimefragment (); One fm.begintransaction () A . Add (R.id.fragmentcontainer, fragment) - . commit (); - } the } -}
The red part is an error because the type is different. But Crimefragment has inherited the fragment, should be automatically transformed.
Think the code error, check several, and finally by the predecessor reminded, import jar package When there is a problem.
In the Mainactivity import is backward compatible import android.support.v4.app.Fragment;
Import Android.app.Fragment is imported in crimeactivity;
Problem Record-fragment Guide package is not automatically transformed