Android. App. Fragment $ instantiationexception Solution
In actual development, I encountered two errors in Android. App. Fragment $ instantiationexception.
When an error is reported, the system prompts "Make sure class name exists, is public, and has an empty constructor that is public". If the fragement definition has a constructor with parameters, you must define the default public constructor. To solve this problem. If you want to include parameters, you can use intent and bunble.
The second error is reported as follows. If "is public, and has an empty constructor that is public" is met, compile the Eng version to run without any problems, however, a crash error occurs when the user version is compiled. The reason is that the user version is obfuscated during compilation.
E/androidruntime (3253): Fatal exception: Main
E/androidruntime (0, 3253): Java. lang. runtimeexception: unable to start activity componentinfo {COM. android. settings/COM. android. settings. subsettings}: Android. app. fragment $ instantiationexception: Unable to instantiate fragment COM. android. settings. mcwill. mcwillsettings:
Make sure class name exists, is public, and has an empty constructor that is public
E/androidruntime (3253): at Android. App. activitythread. initialize mlaunchactivity (activitythread. Java: 1964)
E/androidruntime (3253): at Android. App. activitythread. handlelaunchactivity (activitythread. Java: 1989)
E/androidruntime (3253): at Android. App. activitythread. Access $600 (activitythread. Java: 126)
E/androidruntime (3253): at Android. App. activitythread $ H. handlemessage (activitythread. Java: 1155)
E/androidruntime (3253): at Android. OS. handler. dispatchmessage (handler. Java: 99)
E/androidruntime (3253): at Android. OS. Looper. Loop (Looper. Java: 137)
E/androidruntime (3253): at Android. App. activitythread. Main (activitythread. Java: 4482)
E/AndroidRuntime (3253): at java. lang. reflect. Method. invokeNative (Native Method)
E/AndroidRuntime (3253): at java. lang. reflect. Method. invoke (Method. java: 511)
E/AndroidRuntime (3253): at com. android. internal. OS. ZygoteInit $ MethodAndArgsCaller. run (ZygoteInit. java: 787)
E/AndroidRuntime (3253): at com. android. internal. OS. ZygoteInit. main (ZygoteInit. java: 554)
E/AndroidRuntime (3253): at dalvik. system. NativeStart. main (Native Method)
E/AndroidRuntime (3253): Caused by: android. app. fragment $ InstantiationException: Unable to instantiate fragment com. android. settings. mcwill. mcWiLLSettings: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime (3253): at android. app. Fragment. instantiate (Fragment. java: 581)
E/androidruntime (3253): at Android. Preference. preferenceactivity. switchtoheaderinner (preferenceactivity. Java: 1120)
E/androidruntime (3253): at Android. Preference. preferenceactivity. switchtoheader (preferenceactivity. Java: 1136)
E/androidruntime (3253): at Android. Preference. preferenceactivity. oncreate (preferenceactivity. Java: 532)
E/androidruntime (3253): At com. Android. settings. settings. oncreate (settings. Java: 99)
E/androidruntime (3253): at Android. App. activity. initialize mcreate (activity. Java: 4465)
E/androidruntime (3253): at Android. App. instrumentation. callactivityoncreate (instrumentation. Java: 1049)
E/androidruntime (3253): at Android. App. activitythread. initialize mlaunchactivity (activitythread. Java: 1928)
E/androidruntime (3253):... 11 more
E/androidruntime (3253): caused by: Java. Lang. classnotfoundexception: COM. Android. settings. mcwill. mcwillsettings
E/androidruntime (3253): At Dalvik. system. basedexclassloader. findclass (basedexclassloader. Java: 61)
E/androidruntime (3253): At java. Lang. classloader. loadclass (classloader. Java: 501)
E/androidruntime (3253): At java. Lang. classloader. loadclass (classloader. Java: 461)
E/androidruntime (3253): at Android. App. Fragment. instantiate (fragment. Java: 571)
E/androidruntime (3253):... 18 more
W/activitymanager (422): Force finishing activity com. Android. Settings/. subsettings
W/activitymanager (422): Force finishing activity com. Android. Settings/. Settings
Solution:
Introduce the class package of the fragment to the proguard. Flags file of the corresponding module. For example,-keep class com. Android. settings. Wifi. * settings