gpt4 book ai didi

reactjs - 如何修复这个 React Native 错误 :"java.lang.String cannot be cast to com.facebook.react.uimanager"?

转载 作者:行者123 更新时间:2023-12-02 10:41:55 24 4
gpt4 key购买 nike

我使用以下代码段创建了一个新按钮,但出现“ java.lang.String cannot be cast to com.facebook.react.uimanager.AccessibilityDelegateUtil$AccessibilityRole ”错误。我做了一些挖掘,似乎这是由于 React Native 0.57.3 不稳定导致的错误,所以我按照许多论坛帖子的建议降级到 0.57.1​​。但是错误仍然存​​在,所以如果您可以查看我的代码并给我建议,我将不胜感激。

我的代码:

import React, {Component} from 'react';
import {StyleSheet, Text, View} from 'react-native';

import FetchLocation from './components/FetchLocation';

export default class App extends React.Component{
getUserLocationHandler = () => {

}
render() {
return (
<View style={styles.container}>
<FetchLocation onGetLocation={this.getUserLocationHandler} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});

还有我的代码:
  import React from 'react';
import { Button } from 'react-native';

const fetchLocation = props => {
return (
<Button title="Get Location" onPress={props.onGetLocation}/>
);
};

export default fetchLocation;

这是错误的图像:
Error:

最佳答案

您的版本是 0.57 而 Error when trying to use Button in react-native说它适用于0.55版本。最好试一试。

编辑

我自己尝试了一下,找到了这个解决方案。将 react-native 降级到 57.2 并确保降级其他依赖项,如下所示,

    "dependencies": {
"react": "16.5.0",
"react-native": "0.57.2"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.47.1",
"react-test-renderer": "16.5.0"
}

然后尝试删除 node_modules 并执行 npm install & npm start -- --reset-cache

关于reactjs - 如何修复这个 React Native 错误 :"java.lang.String cannot be cast to com.facebook.react.uimanager"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52911575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com