Android 4.2+ Activity.OnCreate Fragment

时间:2018-01-02 08:38:56

标签: android exception

Google Play开发者控制台多次显示此错误,但我根本无法重现它。此外,我无法理解,我做错了什么。

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2340)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2390)
  at android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:4072)
  at android.app.ActivityThread.access$900 (ActivityThread.java:151)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1270)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:136)
  at android.app.ActivityThread.main (ActivityThread.java:5413)
  at java.lang.reflect.Method.invokeNative (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:970)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:786)
  at dalvik.system.NativeStart.main (Native Method)
Caused by: android.app.Fragment$InstantiationException: 
  at android.app.Fragment.instantiate (Fragment.java:601)
  at android.app.FragmentState.instantiate (Fragment.java:98)
  at android.app.FragmentManagerImpl.restoreAllState (FragmentManager.java:1759)
  at android.app.Activity.onCreate (Activity.java:905)
  at ru.ytaxi40reg.taxi.RegistrationActivity.onCreate (RegistrationActivity.java:58)
  at android.app.Activity.performCreate (Activity.java:5258)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1099)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2280)
Caused by: java.lang.InstantiationException: 
  at java.lang.Class.newInstanceImpl (Native Method)
  at java.lang.Class.newInstance (Class.java:1208)
  at android.app.Fragment.instantiate (Fragment.java:590)

是的,我看到Android cannott实例化了frament。但我的应用程序根本不使用任何碎片!

你能解释一下我错在哪里吗?提前谢谢。

修改:这是RegistrationActivity.java的第58行

...
56  @Override
57  public void onCreate(Bundle p1) {
58      super.onCreate(p1);
59      setContentView(R.layout.activity_registration);
60      // Other stuff
...

编辑2 gist.gitub.com

上的所有文件

1 个答案:

答案 0 :(得分:0)

看起来系统可能会在某些Android设备上将Bundle savedInstanceState作为Activity.OnCreate()方法的参数放错。

我的解决方法是使用以下行替换Activity的onCreate()方法的开头:

@Override
public void onCreate(Bundle p1) {

    try{
        super.onCreate(p1);
    }catch(android.app.Fragment.InstantiationException e){
        super.onCreate(null);

    ...
}