且构网

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

异常马上蝙蝠

更新时间:2023-02-02 21:32:09

小写f被需要的布局。

<片断> 是一个特殊的标签除$ P由活动PTED而不是$ 被实例化一个普通的类(例如,的LinearLayout )。

 < XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=htt​​p://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>