如何解决此React Native错误:“ java.lang.String无法转换为com.facebook.react.uimanager”?

时间:2018-10-21 02:02:51

标签: reactjs react-native error-handling compiler-errors react-redux

我使用以下代码段创建了一个新按钮,但出现“ java.lang.String无法转换为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:

1 个答案:

答案 0 :(得分:2)

您的版本为0.57,而Error when trying to use Button in react-native表示它适用于0.55版本。最好尝试一下。

修改

我自己尝试过,找到了解决方案。将原生版本降级到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