这是日志猫:
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
这是基本设置:
FragmentActivity 包含三个内部类(所有片段)。它们都是使用 ViewPager 和 Support Library 的选项卡。此 Activity 是应用程序首次启动时加载的内容(嗯,在启动屏幕之后)。当应用程序已经打开并且一切正常时会发生此 LogCat 错误;但似乎如果您在此 FragmentActivity 中离开应用程序并稍后再回来,当您尝试恢复时,它将强制关闭。一旦您尝试再次加载它(在强制关闭后),它将返回到启动屏幕,之后一切正常。第 73 行错误位于 Fragment Activity 的顶部。
这是第 73 行:
super.onCreate(savedInstanceState);
这是代码,MasterFrag 内部类的开头:
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);
}