As I dive into learning React Native, I encountered an issue with the Button component in my sample app. The error appears as a red background on my Android Lollipop 5.1 smartphone.
java.lang.String cannot be cast to
com.facebook.react.uimanager.AccessiblityDelegate$AccessibilityRole
setDelegate
AccessbilityDelegateUtil.java:93
updateViewAccessibility
BaseViewManager.java:260
// additional stack trace information
The App.js
file contains the following code which is error-free in VS Code:
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Button} from 'react-native';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'This was edited by Shukant Pal for testing',
});
type Props = {};
export default class App extends Component<Props> {
_startGame = () => {
}
_loadExistingGame = () => {
}
_loadTemplateLibrary = () => {
}
_displayAboutUs = () => {
}
render() {
return (
<View style={styles.container}>
<Text>This works</Text>
<View style={styles.container}>
<Button onPress={this._startGame} title="New Game" />
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
Before posting this question, I performed the following checks:
Imported Button from react-native
Prior to
onPress={this._startGame}
, errors were occurring. Resolving them involved changing method declarations fromname()
toname = () => {}
. Can someone offer insight as to why? (I am new to React and React Native)