Search code examples
javascriptreact-nativeandroid-activityreact-native-splash-screen

React Native - Splash Screen Error ( cannot find symbol ) in MainActivity


I try to add Splash Screen to my React Native Project.
I use this npm package "react-native-splash-screen".
According to this npm package, I change the MainActivity.java file to:

//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());
  }
}

So, this gives me an error:

error: cannot find symbol
  protected void onCreate(Bundle savedInstanceState) {
                          ^
  symbol:   class Bundle
  location: class MainActivity

Solution

  • You need to add import android.os.Bundle; on the top of MainActivity.java file

    import android.os.Bundle; // <- Add this line
    import org.devio.rn.splashscreen.SplashScreen;
    ...