我想用运行FragmentLayout示例程序安卓的minSdkVersion =15
坠毁马上投注做的setContentView(),得到以下异常:
无法启动活动ComponentInfo {net.examples.HelloFragmentLayout / net.examples.HelloFragmentLayout.FragmentLayout}:android.view.InflateException:二进制XML文件,6号线:错误充气类片段
在 net.examples.HelloFragmentLayout / net.examples.HelloFragmentLayout.FragmentLayout
看起来像一个重复的,但我不知道是什么原因造成这一点。
在我的 fragment_layout.xml
(下图),我得到一个警告,这的FrameLayout
可更换合并标记。不知道这有一定影响。
< XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
<片段类=net.examples.HelloFragmentLayout.TitlesFragment
机器人:ID =@ + ID /标题
机器人:layout_width =match_parent
机器人:layout_height =match_parent/>
< /的FrameLayout>
![号称世界头号 毒王 的蝙蝠,究竟有多毒](https://p.xsw88.cn/allimgs/daicuo/20230906/1009.png)
解决方案
小写f被需要的布局。
<片断>
是一个特殊的标签除$ P由活动PTED而不是$
被实例化一个普通的类(例如,的LinearLayout
)。
< XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
<片段类=net.examples.HelloFragmentLayout.TitlesFragment
机器人:ID =@ + ID /标题
机器人:layout_width =match_parent
机器人:layout_height =match_parent/>
< /的FrameLayout>
I am trying to run the FragmentLayout sample program using android:minSdkVersion="15"
It crashed right off the bet doing SetContentView(), getting below exception:
Unable to start activity ComponentInfo{net.examples.HelloFragmentLayout/net.examples.HelloFragmentLayout.FragmentLayout}: android.view.InflateException: Binary XML file line #6: Error inflating class Fragment
The "net.examples.HelloFragmentLayout/net.examples.HelloFragmentLayout.FragmentLayout
" looks like a repeat but I don't know what caused this.
In my fragment_layout.xml
(below), I am getting a warning "This FrameLayout
can be replaced with a merge tag". Not sure if this has an impact.
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Fragment class="net.examples.HelloFragmentLayout.TitlesFragment"
android:id="@+id/titles"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
解决方案
Lowercase 'f' is needed in the layout.
<fragment>
is a special tag interpreted by the Activity
rather than being instantiated as a normal class (e.g., LinearLayout
).
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment class="net.examples.HelloFragmentLayout.TitlesFragment"
android:id="@+id/titles"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
相关推荐
最新文章