You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

验证步骤

  1. 保存修改后的MainActivity.java文件
  2. 重新编译React Native Android项目(执行npx react-native run-android)
  3. 错误会消失,启动屏功能正常生效

内容的提问来源于stack exchange,提问作者Haider Mukhtar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 21:42:01