Search code examples
javaandroidinstantiationrom

Cannot instantiate settings fragment


I'm trying to add a fragment into the Android Settings app to customize the ROM I'm working on. This is the error I'm getting when it force closes according to the logcat.

E/AndroidRuntime(31496): FATAL EXCEPTION: main
E/AndroidRuntime(31496): 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.pcf.RomSettings: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime(31496):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
E/AndroidRuntime(31496):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2356)
E/AndroidRuntime(31496):    at android.app.ActivityThread.access$600(ActivityThread.java:150)
E/AndroidRuntime(31496):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
E/AndroidRuntime(31496):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(31496):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(31496):    at android.app.ActivityThread.main(ActivityThread.java:5193)
E/AndroidRuntime(31496):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(31496):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(31496):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
E/AndroidRuntime(31496):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
E/AndroidRuntime(31496):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(31496): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.settings.pcf.RomSettings: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime(31496):    at android.app.Fragment.instantiate(Fragment.java:592)
E/AndroidRuntime(31496):    at android.preference.PreferenceActivity.switchToHeaderInner(PreferenceActivity.java:1138)
E/AndroidRuntime(31496):    at android.preference.PreferenceActivity.switchToHeader(PreferenceActivity.java:1154)
E/AndroidRuntime(31496):    at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:539)
E/AndroidRuntime(31496):    at com.android.settings.Settings.onCreate(Settings.java:152)
E/AndroidRuntime(31496):    at android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime(31496):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/AndroidRuntime(31496):    at E/AndroidRuntime(31496):     ... 11 more
E/AndroidRuntime(31496): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.settings.pcf.RomSettings" on path: /system/app/Settings.apk
E/AndroidRuntime(31496):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
E/AndroidRuntime(31496):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime(31496):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime(31496):    at android.app.Fragment.instantiate(Fragment.java:582)
E/AndroidRuntime(31496):    ... 18 more

The class is public and everything. I'm sure the name is right. Here is a link to my Github with the file: https://github.com/konstantinkeller/android_packages_apps_Settings/blob/jb4.2.1/src/com/android/settings/pcf/RomSettings.java

That's the entire package. You can check the XML and everything also. Can anyone help me? Thanks.


Solution

  • I guess the error message is right and your class just isn't in the apk. Try to add your file/package to the proguard.flags file.

    Proguard probably removed the file if it isn't referenced in your code but only as text in xml files.

    ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes.