我的应用程序的主要活动开始正常,工作正常,一切都很好 - 但是如果你切换到另一个应用程序并且应用程序被垃圾收集器销毁,当你移回应用程序时它会在“super.onCreate(savedInstanceState )”。
这是我的 onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(LOG_TAG,"Activity Created");
super.onCreate(savedInstanceState);
... //Other stuff that isn't relevent
}
很简单。除非我使用 taskswitcher 切换,然后在应用程序被垃圾收集器杀死以释放内存后切换回来,否则只要“调用 super.OnCreate(savedInstanceState)”,应用程序就会崩溃。
这是日志:
I/ActivityManager( 629): Start proc ambious.androidtroper for activity ambious.androidtroper/.MainActivity: pid=25512 uid=10016 gids={50016, 3003, 1028}
D/AndroidTroper(25512): Activity Created
E/AndroidRuntime(25512): FATAL EXCEPTION: main
E/AndroidRuntime(25512): java.lang.RuntimeException: Unable to start activity ComponentInfo{ambious.androidtroper/ambious.androidtroper.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment ambious.androidtroper.MainActivity$ArticleFragment: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime(25512): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2350)
E/AndroidRuntime(25512): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2400)
E/AndroidRuntime(25512): at android.app.ActivityThread.access$600(ActivityThread.java:153)
E/AndroidRuntime(25512): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
E/AndroidRuntime(25512): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(25512): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(25512): at android.app.ActivityThread.main(ActivityThread.java:5295)
E/AndroidRuntime(25512): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(25512): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(25512): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
E/AndroidRuntime(25512): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
E/AndroidRuntime(25512): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(25512): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment ambious.androidtroper.MainActivity$ArticleFragment: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime(25512): at android.support.v4.app.Fragment.instantiate(Fragment.java:413)
E/AndroidRuntime(25512): at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
E/AndroidRuntime(25512): at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1783)
E/AndroidRuntime(25512): at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:213)
E/AndroidRuntime(25512): at ambious.androidtroper.MainActivity.onCreate(MainActivity.java:88)
E/AndroidRuntime(25512): at android.app.Activity.performCreate(Activity.java:5271)
E/AndroidRuntime(25512): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime(25512): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2304)
E/AndroidRuntime(25512): ... 11 more
E/AndroidRuntime(25512): Caused by: java.lang.InstantiationException: can't instantiate class ambious.androidtroper.MainActivity$ArticleFragment; no empty constructor
E/AndroidRuntime(25512): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(25512): at java.lang.Class.newInstance(Class.java:1130)
E/AndroidRuntime(25512): at android.support.v4.app.Fragment.instantiate(Fragment.java:402)
E/AndroidRuntime(25512): ... 18 more
W/ActivityManager( 629): Force finishing activity ambious.androidtroper/.MainActivity
I/ActivityManager( 629): Process ambious.androidtroper (pid 25512) has died.
现在这很奇怪,因为错误 (ArticleFragment) 中指定的类是公共的,确实有一个公共的空构造函数,并且不会在应用程序的常规启动时导致相同的错误:
public class ArticleFragment extends Fragment {
public ArticleFragment(){
//Empty constructor
}
}
我在这里真的很茫然。该错误在“super.onCreate()”处触发,我不能省略(显然),并且仅在垃圾收集后重新创建应用程序时触发。我错过了什么?还有什么我可能忘记提及的相关内容吗?谢谢你。