我得到了一个
java.lang.IllegalArgumentException: Destination id == 0 can only be used in conjunction with a valid navOptions.popUpTo
当我调用以下代码时:
override fun onNavigateItemClicked(rIdNavAppSectionItem: Int) {
findNavController().navigate(rIdNavAppSectionItem)
}
调试之后,我发现它正在使用rIdNavAppSectionItem == 0调用导航。
那么,我的的来源是什么?
我正在从array.xml读取资源I,所有get调用都会返回0。
我的res/value/array.xml是:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Notice that the android:id value does not include the plus sign in the ID reference,
because the ID already exists, as defined in the ids.xml -->
<integer-array name="main_nav_list">
<item>@id/nav_weighing</item>
<item>@id/nav_water_intake</item>
<item>@id/nav_pill_remainder</item>
</integer-array>
</resources>
我的res/value/ids.xml是:
<?xml version="1.0" encoding="utf-8"?>
<!-- https://developer.android.com/guide/topics/resources/more-resources#Id -->
<!-- Defines a unique ID. Takes no value, only attributes. -->
<resources>
<item type="id" name="nav_home" />
<item type="id" name="nav_weighing" />
<item type="id" name="nav_water_intake" />
<item type="id" name="nav_pill_remainder" />
<item type="id" name="nav_weight_input" />
<item type="id" name="nav_water_intake_input" />
</resources>
我的电话就像:
mRootView.context.resources.getIntArray(R.array.main_nav_list)
返回一个漂亮的0!!数组的
您知道为什么没有初始化这些ids吗?
发布于 2020-09-03 14:26:12
我可以在写问题的时候解决我的问题:
我不知道为什么,但我以前也遇到了一些类似的错误。
并用下面的绘图来解决我过去的问题:Integer array of resource ids returns 0
所以我复制我自己:
val navigations: TypedArray = mRootView.context.resources.getTypedArray(R.array.main_nav_list)
在for索引期间:
val itWantsToGetAnException: Int = 0
val navigate: Int = navigations.getResourceId(index, itWantsToGetAnException)
使用后:
navigations.recycle()
不会再有0岁了!)
祝你今天愉快!!
https://stackoverflow.com/questions/63725696
复制相似问题