Fragment null must be a public static class to be properly recreated from instance state

前端 未结 3 1907
渐次进展
渐次进展 2020-12-12 02:47

I am not able to figure out why my app crashes when getSupportFragmentManager() is called.I have used similar code in other apps to create alert dialogs without any issues.p

相关标签:
3条回答
  • 2020-12-12 02:52

    Your DialogFragment is an anonymous class, and in Java anonymous classes can only be instantiated by parent classes: the new DialogFragment() is in fact this.new DialogFragment(). Apparently, when FragmentManager tries to recreate your DialogFragment upon a configuration change, it can't, since it doesn't have the access to the instance of the parent class. The solution would be to either declare a static subclass of DialogFragment, or to declare a top-level subclass of DialogFragment, and use it instead of the anonymous class.

    0 讨论(0)
  • 2020-12-12 02:58

    I know you have done this step but just asking did you tried to rebuild your APK?because if this code works in other applications then their must be some .classes issue.

    0 讨论(0)
  • 2020-12-12 03:15

    check which type of Fragment you have in your imports whether your'e using android.support.v4.app.Fragment or android.os.Fragment.

    0 讨论(0)
提交回复
热议问题