I am trying to learn React Native and while the sample app works, I get an error, on using the Button component. The error comes in the normal 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
// and more stack trace was given
App.js
contains the following code which does not show any errors 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,
},
});
I did the following checks before posting this question:
Imported Button from react-native
Before
onPress={this._startGame}
was giving errors. After changing the method declarations fromname()
toname = () => {}
that was resolved. Could anyone explain why? (I am new to React and React Native)