본문 바로가기

빈 구멍 채우기

[Android] could not find Fragment constructor

이 로그가 무슨 의미인지 몰라서 한참 헤맸다.

 

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{메인액티비티}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment 커스텀다이얼로그프래그먼트: could not find Fragment constructor
...
Caused by java.lang.NoSuchMethodException: 커스텀다이얼로그프래그먼트.<init> []

 

https://developer.android.com/reference/android/app/Fragment.html#Fragment()

 

Fragment  |  Android 개발자  |  Android Developers

 

developer.android.com

stackoverflow.com/a/64470785/9287140

 

Could not find Fragment constructor

I am facing the issue on some devices and getting an error on my crash analytics. A lot of user devices are facing this issue, but on my device it's working fine. Unable to start activity

stackoverflow.com

developer.android.com/reference/androidx/fragment/app/FragmentFactory

 

FragmentFactory  |  Android 개발자  |  Android Developers

FragmentFactory public class FragmentFactory extends Object java.lang.Object    ↳ androidx.fragment.app.FragmentFactory Interface used to control the instantiation of Fragment instances. Implementations can be registered with a FragmentManager via Fra

developer.android.com

Every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. It is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated;

 

커스텀 다이얼로그 프래그먼트의 생성자는 클릭 리스너를 받는 생성자 하나만 있었다.