错误膨胀类片段 [英] Error inflating class fragment

查看:29
本文介绍了错误膨胀类片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误

Unable to start activity ComponentInfo{de.androidbuch.activiti/de.androidbuch.activiti.task.Activity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment

当我通过纵向和横向模式切换时.我正在使用碎片.我的 xml 是:

when I switch via the portrait and the landscape mode. I'm using fragments. My xml is:

 <LinearLayout android:id="@+id/mainLayout"
               android:orientation="horizontal"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content" >

    <ListView android:id="@+id/android:list"
              android:layout_height="wrap_content"
              android:layout_width="fill_parent"/> 

    <fragment android:id="@+id/fragmentDetails"
              android:layout_height="fill_parent"
              android:layout_width="fill_parent"
              class="de.androidbuch.activiti.task.TaskDetailsFragment"/> 
</LinearLayout>

如果我通过横向和纵向模式切换,一切正常.但是当我点击我的片段(我可以看到我的片段)然后切换到其他模式时,我得到了错误.知道我该如何解决吗?在这里找到了一些答案,但这些都没有帮助我...

If I switch via landscape and portrait mode everything works fine. But when I click on my fragment (and I can see my fragment) and then switch to the other mode I get the error. Any idea how I can solve it? Found some answers here but none of these helped me out...

06-21 14:55:05.600: ERROR/AndroidRuntime(7636): FATAL EXCEPTION: main
06-21 14:55:05.600: ERROR/AndroidRuntime(7636): java.lang.RuntimeException: Unable to start activity         
ComponentInfo{de.androidbuch.activiti/de.androidbuch.activiti.task.Activity}:   android.view.InflateException: Binary XML file line #11: Error inflating class fragment
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3097)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.access$1600(ActivityThread.java:123)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:997)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.os.Looper.loop(Looper.java:126)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.main(ActivityThread.java:3998)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at java.lang.reflect.Method.invokeNative(Native Method)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at java.lang.reflect.Method.invoke(Method.java:491)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at dalvik.system.NativeStart.main(Native Method)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.Activity.setContentView(Activity.java:1771)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at de.androidbuch.activiti.task.TaskActivity.onCreate(TaskActivity.java:83)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     ... 12 more

推荐答案

正如 hdemirchian 所说,确保使用:

As hdemirchian said, make sure to use:

import android.support.v4.app.Fragment;

还要确保使用片段的 Activity 扩展 FragmentActivity 而不是常规的 Activity

And also make sure that the Activity that is using the fragment(s) extends FragmentActivity instead of the regular Activity,

import android.support.v4.app.FragmentActivity;

获取FragmentActivity 类.

这篇关于错误膨胀类片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆