安卓App运行崩溃:Button控件XML加载失败(InflateException)求助
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:
- The Button with id
backedbackgroundusesandroid:background="@drawable/first" - The Button with id
button2usesandroid:background="@drawable/signupfrontbackground"
Step-by-Step Fixes
Verify your drawable resources exist and are valid
Head to yourres/drawablefolder and check iffirst.xml(or its corresponding file) andsignupfrontbackground.xmlexist. 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 inres/values), you're using the wrong resource type reference.For example, if
firstis a color resource, change the background reference to@color/firstinstead of@drawable/first.Check for name conflicts
Notice that your first Button also usesstyle="@style/first"—if you named a style and a drawable with the same namefirst, 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-generatedR.javafile (underapp/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 toBuild > Clean Project, thenBuild > Rebuild Projectto 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




