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

安卓App启动崩溃:Error inflating class AppBarLayout

Fixing "Error inflating class android.support.design.widget.AppBarLayout" Crash in Your Celeb Guess App

Hey there, let's get your celebrity guess app up and running again! The crash you're seeing is caused by a missing dependency—your app can't find the AppBarLayout class because the Design Support Library (which contains this component) isn't included in your project. Let's walk through the fixes step by step:

Step 1: Add the Design Support Library Dependency

Open your app-level build.gradle file (usually located at app/build.gradle) and add the following line to the dependencies block:

implementation 'com.android.support:design:28.0.0'

Important: Make sure this version number matches the version of your other Support Library dependencies (like com.android.support:appcompat-v7—it should be the same, e.g., 28.0.0).

Step 2: Sync Your Gradle Project

Click the Sync Now button that appears in the top-right corner of Android Studio after modifying the build.gradle file. This will download the library and add it to your project.

Step 3: Clean & Rebuild (If Needed)

If you still see the error after syncing, try cleaning and rebuilding your project to clear cached build files:

  • Go to Build > Clean Project
  • Then go to Build > Rebuild Project

Quick Validation Checks

  • Your activity_main.xml uses the correct full class name for AppBarLayout (android.support.design.widget.AppBarLayout)—which it does, so that's already set correctly.
  • Your app's theme extends Theme.AppCompat (yours uses Theme.AppCompat.Light.DarkActionBar), which is required for Design Support Library components to function properly.

Once you've completed these steps, your app should inflate the AppBarLayout without crashing, and you can get back to refining your celebrity guess game!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:01:18