FragmentActivity:不能投从片段派生类 [英] FragmentActivity: Cannot cast from Fragment to derived class
本文介绍了FragmentActivity:不能投从片段派生类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用一个片段在FragmentActivity像这样:
I am trying to use a Fragment in a FragmentActivity like so:
TutViewerFragment viewer = (TutViewerFragment)
getSupportFragmentManager().findFragmentById(R.id.tutview_fragment);
和我的 TutViewerFragment
扩展片段
。但是我得到一个错误:
And my TutViewerFragment
extends Fragment
. However I am getting an error:
不能从片段转换为TutViewerFragment。
Cannot cast from Fragment to TutViewerFragment.
我真的不明白为什么会这样。为什么不能定投?
I really don't understand why this is happening. Why can't it be cast?
推荐答案
正在扩展错误的片段类。导入 android.support.v4.app.Fragment
而不是 android.app.Fragment
。
You are extending the wrong Fragment class. Import android.support.v4.app.Fragment
instead of android.app.Fragment
.
这篇关于FragmentActivity:不能投从片段派生类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文