React Native - MainActivity 中的闪屏错误(找不到符号)

问题描述 投票:0回答:1

我尝试将闪屏添加到我的 React Native 项目中。 我使用这个 npm 包“react-native-splash-screen”。 根据这个npm包,我将MainActivity.java文件更改为:

//splash screen
import org.devio.rn.splashscreen.SplashScreen;

public class MainActivity extends ReactActivity {

  // splash screen
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this);
    super.onCreate(savedInstanceState);
  }

  protected String getMainComponentName() {
    return "ABC";
  }

  @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new DefaultReactActivityDelegate(
        this,
        getMainComponentName(),
        // If you opted-in for the New Architecture, we enable the Fabric Renderer.
        DefaultNewArchitectureEntryPoint.getFabricEnabled());
  }
}

所以,这给了我一个错误:

error: cannot find symbol
  protected void onCreate(Bundle savedInstanceState) {
                          ^
  symbol:   class Bundle
  location: class MainActivity
javascript react-native android-activity react-native-splash-screen
1个回答
0
投票

您需要在 MainActivity.java 文件顶部添加

import android.os.Bundle;

import android.os.Bundle; // <- Add this line
import org.devio.rn.splashscreen.SplashScreen;
...
© www.soinside.com 2019 - 2024. All rights reserved.