Код: Выделить всё
val listener = object : GameHistoryAdapter.RecyclerViewOnClickListener {
override fun onClick(v: View?, position: Int) {
val selectedItem = viewModel.getHistory()[position]
if (selectedItem is RandomWords) {
val resultViewModel: RandomWordsResultViewModel by hiltNavGraphViewModels(R.id.main_navigation)
resultViewModel.setRandomWordsResult(selectedItem)
resultViewModel.isGameCompleted = false
findNavController().navigate(R.id.action_gameHistoryFragment_to_gameOnTimeResultFragment)
} else if (selectedItem is OwnText) {
val resultViewModel : OwnTextResultViewModel by hiltNavGraphViewModels(R.id.main_navigation)
resultViewModel.setOwnTextResult(selectedItem)
resultViewModel.setTypedWordsList(emptyList())
findNavController().navigate(R.id.action_gameHistoryFragment_to_ownTextResultFragment)
}
}
}
В документации метода Navigation() сказано:
@throws IllegalStateException, если текущий узел навигации отсутствует
Как мне справиться с таким поведением? Приложение предназначено для одного действия с навигацией Jetpack. Проблема возникает в нескольких местах проекта.
Код: Выделить всё
Exception java.lang.IllegalArgumentException:
at androidx.navigation.NavController.navigate (NavController.kt:1540)
at androidx.navigation.NavController.navigate (NavController.kt:1472)
at androidx.navigation.NavController.navigate (NavController.kt:1454)
at androidx.navigation.NavController.navigate (NavController.kt:1437)
at com.xxx.yyy.ui.fragment.history.GameHistoryFragment$onViewCreated$listener$1.onClick (GameHistoryFragment.kt:41)
at com.xxx.yyy.adapter.history.GameHistoryAdapter$RandomWordsViewHolder.onClick (GameHistoryAdapter.kt:90)
at android.view.View.performClick (View.java:7448)
at android.view.View.performClickInternal (View.java:7421)
at android.view.View.access$3700 (View.java:838)
at android.view.View$PerformClick.run (View.java:28870)
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:201)
at android.os.Looper.loop (Looper.java:288)
at android.app.ActivityThread.main (ActivityThread.java:7941)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:553)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)
Код: Выделить всё
val node = findDestination(destId)
if (node == null) {
val dest = NavDestination.getDisplayName(context, destId)
require(navAction == null) {
"Navigation destination $dest referenced from action " +
"${NavDestination.getDisplayName(context, resId)} cannot be found from " +
"the current destination $currentNode"
}
throw IllegalArgumentException(
"Navigation action/destination $dest cannot be found from the current " +
"destination $currentNode"
)
}
Код: Выделить всё
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public fun findDestination(@IdRes destinationId: Int): NavDestination? {
if (_graph == null) {
return null
}
if (_graph!!.id == destinationId) {
return _graph
}
val currentNode = backQueue.lastOrNull()?.destination ?: _graph!!
return currentNode.findDestination(destinationId)
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... eexception
Мобильная версия