본문 바로가기
IT/Android

Kotlin] 안드로이드 Fragment findViewById Null

by 깻잎쌈 2021. 5. 22.
반응형
 

[안드로이드] Fragment에서 findViewById 에러 해결 방법

Fragment에서 findViewById error Fragment에서 바인딩을 위해 findViewById() 함수를 사용한다면 다음과 같은 오류가 발생합니다. java.lang.NullPointerException: Attempt to invoke virtual method 'android.v..

swalloow.tistory.com

 

 

override fun onCreateView(
            inflater: LayoutInflater, container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View? {  

        val view = inflater.inflate(R.layout.fragment, container, false)
        val button :Button = view.findViewById(R.id.button)

        return view
}
반응형

댓글