首页 > 解决方案 > 错误:将 gradle 从 appcompat:1.2.0 更新为 appcompat:1.3.1 时出现“ID 未引用此 Activity 中的视图”

问题描述

我从以下位置更新了 gradle 文件中的组件:

implementation 'androidx.appcompat:appcompat:1.2.0'

implementation 'androidx.appcompat:appcompat:1.3.1'

并开始收到这些错误:

Error inflating class fragment
ID does not reference a View inside this Activity

在 onCreateView 期间从 startDestination 片段调用此调用:

navController = Navigation.findNavController(getActivity(), R.id.nav_host_fragment);

当我切换回:

implementation 'androidx.appcompat:appcompat:1.2.0'

问题消失了。有人成功通过此更新管理吗?如果有,步骤是什么?

更新

从 activity_main.xml 请求的 XML

    <fragment
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        app:navGraph="@navigation/nav_graph"
        app:defaultNavHost="true" />

标签: androidandroid-appcompatandroid-navigation-graph

解决方案


推荐阅读