You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

安卓App运行崩溃:Button控件XML加载失败(InflateException)求助

Fixing Android View InflateException for Button Background

Hey there, let's break down why your app keeps crashing and how to fix it!

First, let's look at the error you're getting—this tells us exactly what's wrong:

Caused by: android.view.InflateException: Binary XML file line #51: Error inflating class Button. Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070063 a=-1 r=0x7f070063}

The key part here is "Resource is not a Drawable"—you're trying to use a resource that's not a valid Drawable (like a shape, bitmap, or state selector) as the background for one of your Buttons.

Let's Check Your XML Code

Looking at your layout, two Buttons are using drawable resources for their backgrounds:

  1. The Button with id backedbackground uses android:background="@drawable/first"
  2. The Button with id button2 uses android:background="@drawable/signupfrontbackground"

Step-by-Step Fixes

  • Verify your drawable resources exist and are valid
    Head to your res/drawable folder and check if first.xml (or its corresponding file) and signupfrontbackground.xml exist. Make sure these files are valid Drawable resources—like a shape drawable, state selector, or bitmap. If either of these is actually a color or style (stored in res/values), you're using the wrong resource type reference.

    For example, if first is a color resource, change the background reference to @color/first instead of @drawable/first.

  • Check for name conflicts
    Notice that your first Button also uses style="@style/first"—if you named a style and a drawable with the same name first, this can confuse the resource system. Double-check that you're referencing the correct resource type for each attribute.

  • Pinpoint the problematic resource ID
    The error includes a resource ID: r=0x7f070063. You can look this up in your auto-generated R.java file (under app/build/generated/not_namespaced_r_class_sources/debug/r/your/package/name/R.java) to see exactly which resource this points to. This will confirm if it's a color, style, or something else being incorrectly used as a Drawable.

  • Clean and rebuild your project
    Sometimes Android Studio's resource cache gets corrupted. Go to Build > Clean Project, then Build > Rebuild Project to refresh all resources.

Bonus: Fix a Minor EditText Issue

While not causing the crash, your third EditText has a typo in inputType: android:inputType="textPa" should be android:inputType="textPassword" to properly handle password input.

Give these steps a try—this should resolve the InflateException and get your app running again!

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

火山引擎 最新活动