React Native中的Android应用程序模拟器一直停止运行

3
我正在编辑一个 '.js' 文件,在进行一些更改后保存了我的工作。当我在模拟器上键入“rr”以刷新应用程序时,我一直收到此消息。
Android 应用程序模拟器一直停止 应用信息 关闭应用 进入图像描述 在我的项目中的可视化代码编辑器下创建了 Form.js 并将其导入到我的 Login.js 中的组件文件夹下,这就是错误开始出现的地方。我不知道我做错了什么。我是 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
- Paras Korat
感谢@ParasKorat的回复。我撤销了我的更改,通过退出和关闭命令行停止了节点,重新打开了命令行,cd到正确的目录文件夹,并运行了[react-native run-android]命令。我仍然得到相同的错误。 - Supreme2717
抱歉给您带来不便。请尝试以下方法:从模拟器中卸载该应用程序,首先通过以下命令清理您的Android Gradle:"cd android",然后运行".\gradlew clean"。之后再重新运行应用程序。 - Paras Korat
请尝试我下面写的答案。 - Paras Korat
你好,谢谢你的提醒,请问我在哪里可以找到“正确答案”的选项? - Supreme2717
显示剩余2条评论
1个回答

0

这是您的解决方案
您的应用程序崩溃是因为TextInput中的这个属性underlineColorAndroid="rgba(0,0,0,0)",还有输入框样式的小改动,将字符串值marginVertical: "10"删除并改为marginVertical: 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---
  }
});

输出:--

enter image description here


非常感谢@ParasKorat。通过正确的语法将字符串类型更改为整数类型是解决问题的关键。至于注释掉//underlineColorAndroid='rgba(0,0,0,0)',是因为我使用不正确吗?在阅读https://codedaily.io/tutorials/3/Remove-the-Underline-from-Android-TextInputs-in-React-Native后,它在页面的前半部分附近列出了语法应该是underlineColorAndroid="#ff0000"、underlineColorAndroid="red"或underlineColorAndroid="rgb(255,0,0)"。 - Supreme2717
我是否应该使用"rgb(x,x,x)"而不是"rgb(x,x,x,x)"?再次感谢您的帮助。 - Supreme2717
@Supreme2717 如果这对您有帮助并解决了您的问题,请不要忘记将其标记为正确答案。这有助于其他人更轻松地找到解决方案。 - Shashin Bhayani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接