gpt4 book ai didi

android - 异常立即发生

转载 作者:太空狗 更新时间:2023-10-29 12:53:49 26 4
gpt4 key购买 nike

我正在尝试使用 android:minSdkVersion="15"运行 FragmentLayout 示例程序

它在执行 SetContentView() 时立即崩溃,出现以下异常:

Unable to start activity ComponentInfo{net.examples.HelloFragmentLayout/net.examples.HelloFragmentLayout.FragmentLayout}: android.view.InflateException: Binary XML file line #6: Error inflating class Fragment

net.examples.HelloFragmentLayout/net.examples.HelloFragmentLayout.FragmentLayout”看起来像是重复,但我不知道是什么原因造成的。

在我的 fragment_layout.xml(如下)中,我收到警告“此 FrameLayout 可以用合并标记替换”。不确定这是否有影响。

<?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>

最佳答案

布局中需要小写的“f”。

<fragment>是由 Activity 解释的特殊标签而不是被实例化为普通类(例如 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>

关于android - 异常立即发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9042493/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com