Here is log cat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.---.rate_this/com.kickinglettuce.---.MasterCat}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.---.---.MasterCat$MasterFrag: make sure class name exists, is public, and has an empty constructor that is public
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.---.---.MasterCat$MasterFrag: make sure class name exists, is public, and has an empty constructor that is public
at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1760)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:200)
at com.---.---.MasterCat.onCreate(MasterCat.java:73)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
Caused by: java.lang.InstantiationException: can't instantiate class com.kickinglettuce.rate_this.MasterCat$MasterFrag; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.support.v4.app.Fragment.instantiate(Fragment.java:388)
... 18 more
Here is basic setup:
FragmentActivity contains three inner classes (all fragments). They are all tabs using ViewPager and Support Library. This Activity is what loads when the app first starts (well, after the splash screen that is). This LogCat error happens when app is already open and everything works great; but it seems if you leave the app while in this FragmentActivity and comeback later, it will force close when you try to resume. Once you try to load it again (after the force close), it will go back to the Splash screen and everything works great after. The Line 73 error is at the top of the Fragment Activity.
Here is line 73:
super.onCreate(savedInstanceState);
Here is the code, the beginning of MasterFrag inner class:
public class MasterFrag extends ListFragment {
// some fields
public MasterFrag() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.mastercat, container, false);
}
Try making
MasterFraga class in its own file, or declaring it static. I believe the framework can’t instantiate instance classes.I guess it works fine when you’re creating the fragments yourself, but as you found out, when the framework kicks in, it can’t deal with your inner classes.