Turn-android.app.fragment$instantiationexception Solution

Source: Internet
Author: User

In the actual development, I encountered two times android.app.fragment$instantiationexception error.

One of the errors, according to the error message "Make sure class name exists, are public, and have an empty constructor that is public", if the fragement is defined with a parameter constructor, then Be sure to define the default constructor for public. To resolve this issue. If the hard to carry the parameters in, can be carried in the way intent combined with bunble.

The second error follows the log information posted below, in the case of "is public, and have an empty constructor that is public", the compilation of the Eng version runs without any problems, but the compilation of the user version will cause a crash error. This is because the code is confusing when the user version is compiled.

E/androidruntime (3253): FATAL exception:main

E/androidruntime (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 have an empty constructor that is P Ublic

E/androidruntime (3253): at Android.app.ActivityThread.performLaunchActivity (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 have an empty constructor that is P Ublic
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.performCreate (activity.java:4465)
E/androidruntime (3253): at Android.app.Instrumentation.callActivityOnCreate (instrumentation.java:1049)
E/androidruntime (3253): at Android.app.ActivityThread.performLaunchActivity (activitythread.java:1928)
E/androidruntime (3253): ... One 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): ... More
W/activitymanager (422): Force finishing Activity com.android.settings/. Subsettings
W/activitymanager (422): Force finishing Activity com.android.settings/. Settings

Workaround:

The class package of the fragment is introduced in the Proguard.flags file of the corresponding module. For example:-keep class Com.android.settings.wifi.*settings

Turn-android.app.fragment$instantiationexception Solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.