android 无法示例化片段com.swmansion.rnscreens,屏幕

uujelgoq  于 2023-02-20  发布在  Android
关注(0)|答案(3)|浏览(236)

我一直在使用React Native 0.60.4开发一个安卓和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) 
rsl1atfo

rsl1atfo1#

将其添加到您的MainActivity.java

import android.os.Bundle;

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

zyfwsgd62#

MainActivity.java中添加

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

说明:www.example.comhttps://github.com/software-mansion/react-native-screens#android
示例:

package com.example_app;

import android.os.Bundle; // required for onCreate parameter
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

public class MainActivity extends ReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "example_app";
  }

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

  @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName()) {
      @Override
      protected ReactRootView createRootView() {
      return new RNGestureHandlerEnabledRootView(MainActivity.this);
      }
    };
  }
}
91zkwejq

91zkwejq3#

只是另一种方法:

context.supportFragmentManager.addFragmentOnAttachListener { _,_ -> context.savedStateRegistry.unregisterSavedStateProvider("android:support:fragments")}

相关问题