首页 > 解决方案 > 使用 androidx.fragment.app.FragmentContainerView 时出现 ClassNotFoundException

问题描述

我正在尝试从使用 a 过渡FrameLayout到 usingFragmentContainerView以及我看过的教程,这应该很容易。但是,当我在进行更改后运行我的应用程序时,我得到了

Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: java.lang.ClassNotFoundException: androidx.fragment.app.FragmentContainerView

我的布局文件非常简单:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="@layout/app_bar_main">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragment_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

我需要在我的 build.gradle 中添加一些东西吗?为什么找不到类?

标签: androidandroid-fragments

解决方案


这是androidx.fragment1.2.0 或更高版本:

implementation "androidx.fragment:fragment:1.2.0"

推荐阅读