首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:在android上运行react本机应用程序时,无法读取属性“设置”为null

TypeError:在android上运行react本机应用程序时,无法读取属性“设置”为null
EN

Stack Overflow用户
提问于 2022-03-17 23:56:22
回答 1查看 715关注 0票数 1

我有一个在iOS上运行良好的React本地应用程序,但是当我尝试在Android上运行时,我会得到以下错误。

代码语言:javascript
复制
 ERROR  TypeError: Cannot read property 'settings' of null, js engine: hermes
     ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
          This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
     ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
          This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

谷歌这些错误,我得到建议删除节点模块或运行的反应-本机-清洁项目,我已经尝试了,但没有结果。有什么方法可以获得关于这些错误的更具体的信息吗?这个应用程序很大,所以我不确定TypeError在哪里发生。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-15 15:23:16

你用i18next吗?对我来说,这是i18next配置。检测方法看起来是这样的。

代码语言:javascript
复制
i18next
    .use({
        type:              'languageDetector',
        init:              () => {
        },
        cacheUserLanguage: () => {
        },
        detect:            () => {
            const { SettingsManager, I18nManager } = NativeModules;
            const { settings }                     = SettingsManager;
            let locale;

            if (PlatformHelper.isIOS()) {
                locale = settings.AppleLocale || settings.AppleLanguages[0];
            } else {
                locale = I18nManager.localeIdentifier;
            }

            if (_.isEmpty(locale)) {
                locale = 'en';
            }

            return locale.split('_')[0];
        },
    })

SettingsManager在ios下为null。因此,我们不得不将const { settings } = SettingsManager;移动到PlatformHelper.isIOS()块中。

代码语言:javascript
复制
detect:            () => {
    const { SettingsManager, I18nManager } = NativeModules;
    let locale;

    if (PlatformHelper.isIOS()) {
        const { settings } = SettingsManager;
        locale             = settings.AppleLocale || settings.AppleLanguages[0];
    } else {
        locale = I18nManager.localeIdentifier;
    }

    if (_.isEmpty(locale)) {
        locale = 'en';
    }

    return locale.split('_')[0];
},
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71520374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档