huzit
___을 입력해주세요
huzit
전체 방문자
  • 분류 전체보기 (137)
    • 안드로이드(Compose) (10)
      • UI (4)
      • 개념 (6)
    • 안드로이드 (50)
      • 기본개념 (6)
      • 응용 (4)
      • Debug (18)
      • Binding (3)
      • RecyclerView (5)
      • Firebase (6)
      • Retrofit (1)
      • Activity & Fragment (4)
    • 코틀린 (22)
    • 코딩테스트 (38)
      • 백준 (10)
      • 프로그래머스 (28)
    • 일상 (6)
    • CS 지식 (4)
    • 라즈베리파이 (7)

블로그 메뉴

  • 홈
  • 태그
  • 글쓰기
  • 관리

공지사항

인기 글

태그

  • FCM
  • gts4mini
  • Java
  • recyclerView ClickEvent
  • jetpack
  • Kotlin
  • 공돌카돈
  • RecyclerView
  • 공돌이파파
  • 코틀린
  • 프로그래머스
  • firebase
  • Retrofit
  • Android
  • docker
  • 라즈베리 파이
  • 브레빌 밤비노 플러스
  • IFTTT
  • Debug
  • compose

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
huzit

___을 입력해주세요

java.lang.NullPointerException: null cannot be cast to non-null type androidx.navigation.fragment.NavHostFragment
안드로이드/Debug

java.lang.NullPointerException: null cannot be cast to non-null type androidx.navigation.fragment.NavHostFragment

2023. 4. 18. 01:36
728x90

원인

BottomNavigation을 추가하던 중 

val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragmentContainer) as NavHostFragment

해결

private fun setBottomNav(){
    val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragmentContainer) as NavHostFragment
    //바텀 네비게이션에 들어갈 네비게이션 컨트롤러 정의
    val navController = navHostFragment.findNavController()
    binding.bottomNav.setupWithNavController(navController)
}

호출위치 변경

클래스 프로퍼티에서 호출하던 것을 메서드로 넣어서 Null 가능성을 없앴습니다.

menu의 아이디와 navigation의 아이디가 다를 경우에도 발생할 수 있으니 꼭 breakpoint 찍어보고, id가 같은지 확인하고 시도할 것 추천드립니다.

728x90
저작자표시 (새창열림)

'안드로이드 > Debug' 카테고리의 다른 글

Cannot figure out how to save this field into database. You can consider adding a type converter for it.  (0) 2023.06.12
Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.10 (org.jetbrains.kotlin:kotlin-stdlib:1.8.10) and kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)  (0) 2023.05.25
RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{dcc7ca6 u0 com.***.***/.ble.BleService}  (0) 2023.04.13
--- Failed to create image decoder with message 'unimplemented'  (0) 2023.04.10
Caused by: java.lang.IllegalArgumentException: Char / is not a decimal digit  (0) 2023.04.10
    '안드로이드/Debug' 카테고리의 다른 글
    • Cannot figure out how to save this field into database. You can consider adding a type converter for it.
    • Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.10 (org.jetbrains.kotlin:kotlin-stdlib:1.8.10) and kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)
    • RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{dcc7ca6 u0 com.***.***/.ble.BleService}
    • --- Failed to create image decoder with message 'unimplemented'
    huzit
    huzit
    simple is best

    티스토리툴바