首页 文章

反应原生运行android的错误

提问于
浏览
0

Click here to see the image with error

当我在我的设备上运行react-native run-android时出现此错误,我该如何解决?

I run this :react-native bundle --platform android --dev false --entry-file index.js --bundle-output android / app / src / main / assets / index.android.bundle --assets-dest android / app / SRC /主/ RES

下面的应用和索引文件 .

App.js

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

type Props = {};
export default class App extends Component<Props> {
render() {
return (
  <View style={styles.container}>
    <Text style={styles.welcome}>
      Welcome to React Native!
    </Text>
    <Text style={styles.instructions}>
      To get started, edit App.js
    </Text>
    <Text style={styles.instructions}>
      {instructions}
    </Text>
  </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,
},
});

index.js

import { AppRegistry } from 'react-native';
import App from './App';

AppRegistry.registerComponent('helloworld', () => App);

1 回答

  • 0

    这条线

    ...
    <Text style={styles.instructions}>
      {instructions}
    </Text>
    ...
    

    是指 instructions 来自创建应用程序时生成的样板代码 . 通常,这是在类定义之前 .

    const instructions = Platform.select({
      ios: 'Press Cmd+R to reload,\n' +
      'Cmd+D or shake for dev menu',
      android: 'Double tap R on your keyboard to reload,\n' +
      'Shake or press menu button for dev menu',
    });
    

    显然,你删除了它并没有删除相应的 {instructions} .

    您需要删除 <Text style={styles.instructions}>{instructions}</Text> 或者在您的类定义之上添加上面的代码 .

相关问题