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

onCreate()导致加载Profile Activity时应用崩溃问题求助

解决FloatingActionButton导致的Activity启动崩溃问题

从你的错误日志和布局代码来看,问题根源很明确——FloatingActionButton的属性设置错误,直接导致了profiles_wards Activity加载布局时失败崩溃。咱们一步步来排查修复:

首先看你贴出的核心错误日志:

E/AndroidRuntime: FATAL EXCEPTION: main 
Process: info.sahms.sahms, PID: 8033 
java.lang.RuntimeException: Unable to start activity ComponentInfo{info.sahms.sahms/info.sahms.sahms.profiles_wards}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.FloatingActionButton
...

这个InflateException直接指向FAB的布局解析失败,咱们看你的布局代码里的FAB部分:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|end"
    android:background="@color/yellow"
    android:backgroundTint="@color/yellow"
    android:src="@drawable/ic_face_black_24dp" />

这里有个关键错误:旧版support库的FloatingActionButton不能同时设置android:background和app:backgroundTint,FAB内部已经封装了背景样式,强行设置系统的background属性会破坏它的结构,导致解析失败。

具体修复步骤

1. 修正FAB的属性配置

删掉android:background="@color/yellow",只保留app:backgroundTint="@color/yellow"——这是官方推荐的修改FAB背景色的方式。修改后的代码如下:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|end"
    app:backgroundTint="@color/yellow"
    android:src="@drawable/ic_face_black_24dp" />

2. 检查资源有效性

  • 确认@drawable/ic_face_black_24dp确实存在于res/drawable目录下,没有拼写错误;如果是矢量图,确保你已经配置了support库的矢量图兼容(比如在build.gradle里开启vectorDrawables.useSupportLibrary = true)。
  • 确认@color/yellow在res/values/colors.xml中正确定义,比如:
<color name="yellow">#FFFF00</color>

3. 统一support库版本

检查你的build.gradle(Module)文件,确保所有support相关库的版本完全一致,版本冲突也可能导致布局解析异常:

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'

4. 清理重建项目

有时候Android Studio的缓存会引发奇怪的问题,执行以下操作:

  • 点击菜单栏Build → Clean Project
  • 然后点击Build → Rebuild Project

做完这些步骤后,再启动profiles_wards Activity,应该就能正常加载了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:19:31