React Native添加react-native-splash-screen时MainActivity报找不到符号错误
解决React Native中react-native-splash-screen的Bundle类找不到错误
问题原因
报错cannot find symbol class Bundle是因为Bundle类属于Android SDK核心类,你的MainActivity.java文件未导入该类,导致编译器无法识别它。
解决方案
在文件顶部的导入区域添加Bundle的导入语句即可:
// 新增Bundle类导入 import android.os.Bundle; // 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()); } }
验证步骤
- 保存修改后的MainActivity.java文件
- 重新编译React Native Android项目(执行
npx react-native run-android) - 错误会消失,启动屏功能正常生效
内容的提问来源于stack exchange,提问作者Haider Mukhtar
相关产品推荐
相关产品推荐

