gpt4 book ai didi

android - Robolectric 使用导航架构组件,Resources$NotFoundException : nav_graph

转载 作者:行者123 更新时间:2023-11-29 23:22:17 24 4
gpt4 key购买 nike

我在 android 中运行 robolectric 测试时遇到了麻烦

    <fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />

我正在使用导航架构组件我正在查看通货膨胀异常

下面是我的错误日志

 android.view.InflateException: XML file       C:\Users\StudioProjects\app\build\intermediates\merged-not-compiled-resources\debug\layout\activity_main.xml line #-1 (sorry, not yet implemented): XML file C:\Users\StudioProjects\app\build\intermediates\merged-not-compiled-resources\debug\layout\activity_main.xml line #-1 (sorry, not yet implemented): Error inflating class fragment Caused by: android.view.InflateException: XML file C:\Users\jitendrakumar\StudioProjects\app\build\intermediates\merged-not-compiled-resources\debug\layout\activity_main.xml line #-1 (sorry, not yet implemented): Error inflating class fragment
Caused by: android.content.res.Resources$NotFoundException: packagename:navigation/nav_graph
at org.robolectric.shadows.ShadowLegacyAssetManager.loadXmlResourceParser(ShadowLegacyAssetManager.java:591)
at org.robolectric.shadows.ShadowResources.loadXmlResourceParser(ShadowResources.java:205)
at android.content.res.Resources.loadXmlResourceParser(Resources.java)
at android.content.res.Resources.getXml(Resources.java:1206)
at androidx.navigation.NavInflater.inflate(NavInflater.java:67)
at androidx.navigation.NavController.setGraph(NavController.java:424)
at androidx.navigation.NavController.setGraph(NavController.java:406)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:226)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2414)

我已经启用了

android.useAndroidX=true
android.enableJetifier=true

最佳答案

在 navigation.xml 文件(或您的自定义 res/navigation/*.xml)中查看您的根元素 ID。 ID 必须是“@+id/nav_graph”。示例:

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/homeDestinationFragment">

关于android - Robolectric 使用导航架构组件,Resources$NotFoundException : nav_graph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54087429/

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