You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android应用点击按钮崩溃,请求排查emp.XML文件错误

修复Android布局XML导致的应用崩溃问题

嘿,我仔细看了你贴的emp.XML代码,立刻发现了几个明显的XML语法错误——这些问题会直接导致布局解析失败,进而触发应用崩溃。咱们来一步步解决:

找到的问题点

  • 冗余的无效标签:第一个EditText标签已经正确闭合了,但后面多了一行单独的android:text="" />,这属于无效的XML节点,系统解析布局时会直接报错。
  • 未完成的标签:第二个EditText的代码没写完(最后是android:l...),标签没有完整闭合,同样会让XML解析器卡壳,无法正常加载布局。

修正后的完整XML代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/lawa"
    tools:context="com.example.johnwalls.projet.Main2Activity">

    <EditText
        android:id="@+id/username"
        android:layout_width="150dp"
        android:layout_height="30dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:textSize="10dp"
        android:background="#ffffffff"
        android:textColor="#000"
        android:textColorHighlight="#ffffffff"
        android:phoneNumber="false"
        android:text=""
        style="@android:style/TextAppearance.Large"
        android:textStyle="bold"
        android:typeface="sans"
        android:layout_marginBottom="90dp"
        android:layout_alignBottom="@+id/pass"
        android:layout_alignLeft="@+id/pass"
        android:layout_alignStart="@+id/pass" />

    <EditText
        android:id="@+id/pass"
        android:layout_width="150dp"
        android:layout_height="30dp"
        android:ems="10"
        android:inputType="textPassword"
        android:textSize="10dp"
        android:background="#ffffffff"
        android:textColor="#000"
        android:textColorHighlight="#ffffffff"
        android:phoneNumber="false"
        android:text=""
        style="@android:style/TextAppearance.Large"
        android:textStyle="bold"
        android:typeface="sans"
        android:layout_marginLeft="11dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

额外建议

修复完XML后,记得先执行Build -> Clean Project清理项目缓存,再重新运行应用。如果之后还是崩溃,可以查看Logcat里的错误日志,看看是不是还有其他逻辑层面的问题(比如按钮点击事件里的空指针等)。

内容的提问来源于stack exchange,提问作者john walls

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:00:32