无法实例化片段com.swmansion.rnscreens.Screen

时间:2019-08-29 11:59:02

标签: android react-native androidx

我一直在使用React Native 0.60.4开发适用于android和ios的应用程序,最近我发现将应用程序置于分屏或自由形式模式(因为它是屏幕上唯一的应用程序)有时会导致它崩溃。

我进一步研究了这个问题,发现我可以毫无问题地将应用程序启动到分屏或自由形式模式,但是有时调整它的大小会导致它崩溃。以下是我在Android Studio中调试器实例的输出,我在努力了解这些信息:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.myApp, PID: 32150
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myApp/com.myApp.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.Screen$ScreenFragment: calling Fragment constructor caused an exception
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279)
        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187)
        at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.Screen$ScreenFragment: calling Fragment constructor caused an exception
        at androidx.fragment.app.Fragment.instantiate(Fragment.java:465)
        at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:50)
        at androidx.fragment.app.FragmentState.instantiate(FragmentState.java:80)
        at androidx.fragment.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3109)
        at androidx.fragment.app.FragmentController.restoreAllState(FragmentController.java:158)
        at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:344)
        at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)
        at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
        at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279) 
        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187) 
        at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at androidx.fragment.app.Fragment.instantiate(Fragment.java:443)
        at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:50) 
        at androidx.fragment.app.FragmentState.instantiate(FragmentState.java:80) 
        at androidx.fragment.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3109) 
        at androidx.fragment.app.FragmentController.restoreAllState(FragmentController.java:158) 
        at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:344) 
        at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:85) 
        at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51) 
        at android.app.Activity.performCreate(Activity.java:7802) 
        at android.app.Activity.performCreate(Activity.java:7791) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
        at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279) 
        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187) 
        at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
     Caused by: java.lang.IllegalStateException: Screen fragments should never be restored
        at com.swmansion.rnscreens.Screen$ScreenFragment.<init>(Screen.java:24)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
        at androidx.fragment.app.Fragment.instantiate(Fragment.java:443) 
        at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:50) 
        at androidx.fragment.app.FragmentState.instantiate(FragmentState.java:80) 
        at androidx.fragment.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3109) 
        at androidx.fragment.app.FragmentController.restoreAllState(FragmentController.java:158) 
        at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:344) 
        at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:85) 
        at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51) 
        at android.app.Activity.performCreate(Activity.java:7802) 
        at android.app.Activity.performCreate(Activity.java:7791) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
        at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279) 
        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187) 
        at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 

1 个答案:

答案 0 :(得分:1)

将此添加到您的MainActivity.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(null);
   }