【问题标题】:Android Application Emulator keeps stopping on React NativeAndroid Application Emulator 一直在 React Native 上停止
【发布时间】:2019-07-06 18:24:31
【问题描述】:

我正在编辑其中一个“.js”文件,在进行一些更改后保存我的工作后,当我在模拟器上键入“rr”以刷新应用程序时,我不断收到此消息。

Android 应用程序模拟器不断停止 应用信息 关闭应用

enter image description here

在 Visual Studio 代码编辑器中创建 Form.js 并在我的项目中的组件文件夹下并将其导入我的 Login.js 后,错误开始出现发生。 IDK 我做错了什么。我是 React Native 的新手,正在学习。

Form.js

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

export default class Login extends Component<{}> {
      render(){
          return(
              <View style={styles.container}>
                <TextInput style={styles.inputBox} 
                  underlineColorAndroid='rgba(0,0,0,0)' 
                  placeholder="Email"
                  placeholderTextColor = "#ffffff"
                   />
                <TextInput style={styles.inputBox} 
                  underlineColorAndroid='rgba(0,0,0,0)' 
                  placeholder="Password"
                  placeholderTextColor = "#ffffff"
                   />
                </View>
          )
      }
  }

const styles = StyleSheet.create({
container : {
  flex: 1,
  justifyContent: 'center',
  alignItems: 'center'
},
inputBox: {
  width:300,
  backgroundColor:'rgba(255,255,255,0.3)',
  borderRadius: 25,
  paddingHorizontal: 16,
  fontSize: 16,
  color:'#ffffff',
  marginVertical: '10'

}
});

Login.js

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

import Logo from '../components/Logo';
import Form from '../components/Form';

export default class Login extends Component<{}> {
render () {
return(
  <View style={styles.container}>
    <Logo/>  
    <Form/>      
  </View>
)
}
}

const styles = StyleSheet.create({
container : {
  backgroundColor: '#29b6f6',
  flex: 1,
  alignItems: 'center',
  justifyContent: 'center',
}
});

【问题讨论】:

  • 这是因为您对代码的最后更改。不知何故,它使您的应用程序崩溃。只是停止节点。回滚您的更改。然后再次点击命令react-native run-android
  • 感谢您回复@ParasKorat。我回滚了我的更改,通过退出和关闭命令行来停止节点,重新打开命令行,cd 到正确的目录文件夹,然后运行 ​​[react-native run-android] 命令。我仍然遇到同样的错误。
  • 很抱歉给您带来不便。试试这个,从模拟器中卸载应用程序,先用这个命令“cd android”然后“.\gradlew clean”清理你的android gradle。并再次运行。
  • @ParasKorat,我跟着你的步骤。这是我按顺序执行的操作: 1. 单击“应用程序信息”,然后单击“卸载”。 2.然后我关闭了节点cli,然后关闭了我的命令提示符。 3. 我重新打开命令提示符并 cd 到 (C:\Users\Clint\Desktop\DesktopTings\Reactnative\lulock>cd android) 然后运行 ​​[gradlew clean]。 4.打开一个模拟器。 5. cd 回到根项目和 [react-native run-android]。仍然得到错误。我编辑了我的帖子,详细显示了我对哪些文件所做的更改导致应用程序崩溃。
  • 试试我在下面写的这个答案

标签: android react-native mobile-application


【解决方案1】:

这是您的解决方案
由于 TextInput 中的这个道具 underlineColorAndroid="rgba(0,0,0,0)" 以及 inputBox 样式的微小变化删除字符串值 ma​​rginVertical: "10",您的应用程序崩溃了ma​​rginVertical:10

Form.js

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

export default class Login extends Component {
  render() {
    return (
      <View style={styles.container}>
        <TextInput
          style={styles.inputBox}
          // underlineColorAndroid="rgba(0,0,0,0)"<---Comment this code---
          placeholder="Email"
          placeholderTextColor="#ffffff"
        />
        <TextInput
          style={styles.inputBox}
          // underlineColorAndroid="rgba(0,0,0,0)"<---Comment this code---
          placeholder="Password"
          placeholderTextColor="#ffffff"
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center"
  },
  inputBox: {
    width: 300,
    backgroundColor: "rgba(255,255,255,0.3)",
    borderRadius: 25,
    paddingHorizontal: 16,
    fontSize: 16,
    color: "#ffffff",
    marginVertical: 10 <-----Remove string to number---
  }
});

输出:--

【讨论】:

  • 非常感谢@ParasKorat。通过正确的语法将字符串类型更改为整数类型是修复它的方法。它运行良好,就注释掉 //underlineColorAndroid='rgba(0,0,0,0) 而言,是因为我使用不正确吗?在阅读codedaily.io/tutorials/3/… 之后,它会在页面前半部分附近的某处列出语法应为 underlineColorAndroid="#ff0000"、underlineColorAndroid="red" 或 underlineColorAndroid="rgb(255,0,0)"。跨度>
  • 难道我应该是“rgb(x,x,x)”时才完成了“rgb(x,x,x,x)”?再次感谢您的帮助。
  • @Supreme2717 如果这对您有帮助并解决您的问题,请不要忘记勾选正确答案。它可以帮助其他人轻松找到解决方案。
猜你喜欢
  • 1970-01-01
  • 2022-08-04
  • 1970-01-01
  • 2021-10-30
  • 2021-03-21
  • 2017-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多