Search code examples
androidandroid-studiokotlinandroid-fragmentsoncreate

App crashes when changing into light to dark mode


In my main activity I'm attaching two fragments and using tablayout. Whenever I change light to dark or dark to light, I'm getting this errorenter image description here

    Process: com.umobi.scantags, PID: 24666
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.umobi.scantags/com.umobi.scantags.activities.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.umobi.scantags.fragments.DeactiveFragment: could not find Fragment constructor

and the error is showing in the onCreate() of super.onCreate(savedInstanceState) main activity.


Solution

  • Unable to instantiate fragment com.umobi.scantags.fragments.DeactiveFragment: could not find Fragment constructor

    Your DeactiveFragment needs a zero-argument constructor, or alternatively you need to register a FragmentFactory that instantiates the fragment without a zero-arg constructor.