InflateException以&lt所致;片断>标签如果没有绑定类 [英] InflateException Caused by <fragment> Tag Without a Bound Class

查看:216
本文介绍了InflateException以&lt所致;片断>标签如果没有绑定类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是类和主详细流程,创建新项目时,这是可用的XML布局,有一个列表和详细视图并排侧。不过,我得到这个错误:

  E / AndroidRuntime(724):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.TrueFalse / com.TrueFalse.news.NewsModule}:android.view.InflateException:二进制XML文件行#14:错误充气类片段
E / AndroidRuntime(724):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
E / AndroidRuntime(724):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
E / AndroidRuntime(724):在android.app.ActivityThread.access $ 1500(ActivityThread.java:123)
E / AndroidRuntime(724):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:993)
E / AndroidRuntime(724):在android.os.Handler.dispatchMessage(Handler.java:99)
E / AndroidRuntime(724):在android.os.Looper.loop(Looper.java:126)
E / AndroidRuntime(724):在android.app.ActivityThread.main(ActivityThread.java:3997)
E / AndroidRuntime(724):在java.lang.reflect.Method.invokeNative(本机方法)
E / AndroidRuntime(724):在java.lang.reflect.Method.invoke(Method.java:491)
E / AndroidRuntime(724):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:841)
E / AndroidRuntime(724):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
E / AndroidRuntime(724):在dalvik.system.NativeStart.main(本机方法)
E / AndroidRuntime(724):android.view.InflateException:二进制XML文件行#14:错误充气类片段产生的原因
E / AndroidRuntime(724):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688)
E / AndroidRuntime(724):在android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
E / AndroidRuntime(724):在android.view.LayoutInflater.inflate(LayoutInflater.java:479)
E / AndroidRuntime(724):在android.view.LayoutInflater.inflate(LayoutInflater.java:391)
E / AndroidRuntime(724):在android.view.LayoutInflater.inflate(LayoutInflater.java:347)
E / AndroidRuntime(724):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:224)
E / AndroidRuntime(724):在android.app.Activity.setContentView(Activity.java:1777)
E / AndroidRuntime(724):在com.TrueFalse.news.NewsModule.onCreate(NewsModule.java:19)
E / AndroidRuntime(724):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
E / AndroidRuntime(724):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
E / AndroidRuntime(724):11 ...更多
E / AndroidRuntime(724):显示java.lang.NullPointerException:产生的原因
E / AndroidRuntime(724):在java.lang.VMClassLoader.findLoadedClass(本机方法)
E / AndroidRuntime(724):在java.lang.ClassLoader.findLoadedClass(ClassLoader.java:390)
E / AndroidRuntime(724):在java.lang.ClassLoader.loadClass(ClassLoader.java:538)
E / AndroidRuntime(724):在java.lang.ClassLoader.loadClass(ClassLoader.java:508)
E / AndroidRuntime(724):在android.support.v4.app.Fragment.instantiate(Fragment.java:391)
E / AndroidRuntime(724):在android.support.v4.app.Fragment.instantiate(Fragment.java:369)
E / AndroidRuntime(724):在android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
E / AndroidRuntime(724):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:660)
E / AndroidRuntime(724):20 ...更多

我怀疑这事做的事实,我没有设置任何机器人:名字=或类=,这可以解释的堆栈跟踪,但模板,上面提到的,有这相同的XML从周围的一些名称更改文件分开。

在跟踪我的code的行号

 的setContentView(R.layout.news_list_container);

我NewsModule类扩展android.support.v4.app.FragmentActivity。


/res/values​​-large/refs.xml(图news_list_container.xml到news_twopane_container.xml,对此我相当肯定出现这种情况,是因为它适用于那些不符合大型设备精:约束)

 <?XML版本=1.0编码=UTF-8&GT?;
<资源>    <! - 为支持iPad的风格观点的屏幕布局覆盖列表。
         这应该反映在其他refs.xml文件 - >
    <项目名称=news_list_containerTYPE =布局> @布局/ news_twopane_container< /项目>
< /资源>

/res/layout/news_twopane_container.xml(第14行是第二个片段的开头)

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=横向>    <片段
        机器人:ID =@ + ID / news_list_container
        机器人:名字=com.TrueFalse.news.NewsList
        机器人:layout_width =0dp
        机器人:layout_height =FILL_PARENT
        机器人:layout_weight =1/>    <片段
        机器人:ID =@ + ID / news_detail_container
        机器人:layout_width =0dp
        机器人:layout_height =FILL_PARENT
        机器人:layout_weight =1/>< / LinearLayout中>


解决方案

在我所用的模板,我忽略了一个事实,即第二个片段实际上应该是一个的占位符的一个片段,它在模板是一个的FrameLayout。我原来的嫌疑竟然是问题,因为碎片的必须的与它关联的类。所以/res/news_twopane_container.xml应该是:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=横向>    <片段
        机器人:ID =@ + ID / news_list_container
        机器人:名字=com.TrueFalse.news.NewsList
        机器人:layout_width =0dp
        机器人:layout_height =FILL_PARENT
        机器人:layout_weight =1/>
    <! - NOT片段,因为我们没有数据,但放在这里 - >
    <的FrameLayout
        机器人:ID =@ + ID / news_detail_container
        机器人:layout_width =0dp
        机器人:layout_height =FILL_PARENT
        机器人:layout_weight =1/>< / LinearLayout中>

I am using the classes and xml layouts of the Master-Detail flow, which is available when creating a new project, to have a list and a detail view side-by-side. However, I am getting this error:

E/AndroidRuntime(  724): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.TrueFalse/com.TrueFalse.news.NewsModule}: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
E/AndroidRuntime(  724):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
E/AndroidRuntime(  724):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
E/AndroidRuntime(  724):    at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime(  724):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
E/AndroidRuntime(  724):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  724):    at android.os.Looper.loop(Looper.java:126)
E/AndroidRuntime(  724):    at android.app.ActivityThread.main(ActivityThread.java:3997)
E/AndroidRuntime(  724):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  724):    at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime(  724):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
E/AndroidRuntime(  724):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
E/AndroidRuntime(  724):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  724): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
E/AndroidRuntime(  724):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688)
E/AndroidRuntime(  724):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
E/AndroidRuntime(  724):    at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
E/AndroidRuntime(  724):    at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
E/AndroidRuntime(  724):    at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
E/AndroidRuntime(  724):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:224)
E/AndroidRuntime(  724):    at android.app.Activity.setContentView(Activity.java:1777)
E/AndroidRuntime(  724):    at com.TrueFalse.news.NewsModule.onCreate(NewsModule.java:19)
E/AndroidRuntime(  724):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
E/AndroidRuntime(  724):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
E/AndroidRuntime(  724):    ... 11 more
E/AndroidRuntime(  724): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  724):    at java.lang.VMClassLoader.findLoadedClass(Native Method)
E/AndroidRuntime(  724):    at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:390)
E/AndroidRuntime(  724):    at java.lang.ClassLoader.loadClass(ClassLoader.java:538)
E/AndroidRuntime(  724):    at java.lang.ClassLoader.loadClass(ClassLoader.java:508)
E/AndroidRuntime(  724):    at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
E/AndroidRuntime(  724):    at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
E/AndroidRuntime(  724):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
E/AndroidRuntime(  724):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:660)
E/AndroidRuntime(  724):    ... 20 more

I suspect that it has something to do with the fact that I am not setting either android:name="" or class="", which would explain the stack trace, but the template, mentioned above, had this same xml file apart from changing around some names.

The line number in the trace for my code is

setContentView(R.layout.news_list_container);

My NewsModule class extends android.support.v4.app.FragmentActivity.


/res/values-large/refs.xml (maps news_list_container.xml to news_twopane_container.xml, which I am fairly sure this happens, because it works fine on devices that don't satisfy the "large: constraint.)

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- List of layout overrides for screens that can support iPad style views.
         This should mirror the other refs.xml file-->
    <item name="news_list_container" type="layout">@layout/news_twopane_container</item>
</resources>

/res/layout/news_twopane_container.xml (line 14 is the beginning of the second fragment)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/news_list_container"
        android:name="com.TrueFalse.news.NewsList"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1" />

    <fragment
        android:id="@+id/news_detail_container"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1" />

</LinearLayout>

解决方案

When I was using the template, I overlooked the fact that the second fragment should actually be a placeholder for a fragment, which in the template was a FrameLayout. My original suspicion turned out to be the issue because a fragment must have a class associated with it. so /res/news_twopane_container.xml should be:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/news_list_container"
        android:name="com.TrueFalse.news.NewsList"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1" />
    <!-- NOT fragment, because we don't have data to put here yet -->
    <FrameLayout
        android:id="@+id/news_detail_container"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1" />

</LinearLayout>

这篇关于InflateException以&lt所致;片断&gt;标签如果没有绑定类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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