Type mismatch: cannot convert from MainFragment to Fragment 报错

源码:

1         FragmentTransaction mFragmentTranscation = getSupportFragmentManager().beginTransaction();
2         Fragment mMainFragment = new MainFragment();//此行提示出错
3         mFragmentTranscation.replace(R.id.container, mMainFragment);
4         mFragmentTranscation.commit();

 

错误提示:无法将MainFragment (Fragment的子类)强制转换成Fragment

解决方法:

在原来的MainFragment中把

import android.app.Fragment;

更改为:

import android.support.v4.app.Fragment;

posted @ 2015-01-15 13:22  jenson138  阅读(1397)  评论(1编辑  收藏  举报