且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

InflateException错误充气类片段

更新时间:2023-11-17 13:10:16

如果你正在尝试使用片段支持Android包的反向移植,你需要有你的活动从 FragmentActivity $ C继承$ C>(或者其他什么东西,从 FragmentActivity 继承>,如 SherlockFragmentActivity )。

If you are trying to use the Android Support package's backport of fragments, you need to have your activity inherit from FragmentActivity (or from something else that inherits from FragmentActivity, like SherlockFragmentActivity).

更新

从堆栈跟踪的关键行是:

The key line from your stack trace is:

12-09 20:39:00.317: E/AndroidRuntime(18214): Caused by: java.lang.ClassCastException: com.example.test.Fragment1 cannot be cast to android.app.Fragment

现在,有没有在你提供​​的源$ C ​​$ C,它被命名为 com.example.test.Fragment1 。如果这真的是你在您的物品有作为 com.example.test.FragmentClass1 ,那么presumably的片段你继​​承不是 android.app.Fragment 。最有可能的,在这种情况下,它是 android.support.v4.app.Fragment - 从片段类反向移植的。如果是这样的情况下,改变import语句(并在code基其余任何其他缺陷的)。

Now, there is nothing in your supplied source code that is named com.example.test.Fragment1. If this is really what you have in your listings as com.example.test.FragmentClass1, then presumably the Fragment you are inheriting from is not android.app.Fragment. Most likely, in that case, it is android.support.v4.app.Fragment -- the Fragment class from the backport. If this is the case, change the import statement (and any other flawed ones in the rest of your code base).