question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeCastException in NavigationExtensions.kt

See original GitHub issue

Hello

I am working on a hobby app, using bottom navigation bar. I copied the NavigationExtensions.kt extension file from the NavigationAdvancedSample and I get this exception:

kotlin.TypeCastException: null cannot be cast to non-null type androidx.navigation.fragment.NavHostFragment at com.sanislo.soft.photospot.NavigationExtensionsKt$setupItemReselected$1.onNavigationItemReselected(NavigationExtensions.kt:187) at com.google.android.material.bottomnavigation.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:201) at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840) at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158) at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991) at com.google.android.material.bottomnavigation.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:115) at android.view.View.performClick(View.java:7352) at android.view.View.performClickInternal(View.java:7318) at android.view.View.access$3200(View.java:846) at android.view.View$PerformClick.run(View.java:27800) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7037) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:16

github_iconTop GitHub Comments

147reactions
sanisloandrascommented, Aug 3, 2019

So I figured out that the reason why I was getting this exception because the navigation graphs id in the xml should match the id of the menu items in the bottom navigation menu xml.

I think there should be a red huge warning about this restriction, because I have lost like 5 hours of my life debugging this error…

1reaction
fvaladarescommented, Feb 16, 2021

I had a similar problem, after several hours a discover that I forget to pass the layout as the activity parameter: AppCompatActivity(R.layout.activity_main)

Read more comments on GitHub >

github_iconTop Results From Across the Web

null cannot be cast to non-null type androidx.navigation ...
I copied the NavigationExtensions.kt extension file from the NavigationAdvancedSample and I get this exception:.
Read more >
Kotlin.Typecastexception: Null Cannot Be Cast To ... - ADocLib
Tried to the NavigationExtensions.kt helper class to add navigation to BottomNavigationView, but getting kotlin.TypeCastException: null cannot be cast to.
Read more >
Support multiple back stacks for Bottom tab navigation
Check out NavigationExtensions.kt in the NavigationAdvancedSample. ... TypeCastException: null cannot be cast to non-null type androidx.navigation.fragment.
Read more >
BottomNavigationView와 Navigation Graph를 같이 쓰는 경우
android-architecture-components/NavigationExtensions.kt at master ... TypeCastException in NavigationExtensions.kt · Issue #693 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found