Caused by: android.view.InflateException: Binary XML file line #51: Error inflating class 按钮
Caused by: android.view.InflateException: Binary XML file line #51: Error inflating class Button
嗨,每当我 运行 我的应用程序崩溃时,我检查过 Logcat
它给出了这个错误字符串
我的代码和我的应用程序的结构如下,我一直在寻找答案
并希望有人帮助我。
提前致谢
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}
这是我的 XML
<?xml version="1.0" encoding="utf-8"?> android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<!--tools:layout_editor_absoluteX="16dp"-->
<!--tools:layout_editor_absoluteY="81dp"-->
<android.support.constraint.ConstraintLayout
android:layout_width="135dp"
android:layout_height="203dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="60dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView_login"
style="@style/Longin"
android:layout_width="69dp"
android:layout_height="30dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:text="@string/app_loging"
android:translationZ="3dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.15" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="172dp"
android:layout_height="431dp"
android:layout_marginTop="64dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/backedbackground"
style="@style/first"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:background="@drawable/first"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView_signup"
style="@style/Longin"
android:layout_width="69dp"
android:layout_height="30dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:text="@string/app_singup"
android:textColor="@color/colorwhite"
android:translationZ="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.908"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="312dp"
android:layout_height="319dp"
android:layout_marginTop="124dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/signupfrontbackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="62dp"
android:layout_marginTop="24dp"
android:drawableRight="@drawable/ic_user_male_black_shape"
android:ems="10"
android:hint="User name"
android:inputType="textPersonName"
android:translationZ="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:drawableRight="@drawable/ic_envelope"
android:ems="10"
android:hint="@string/app_Email"
android:inputType="textEmailAddress"
android:translationZ="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.329" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="59dp"
android:layout_marginTop="140dp"
android:drawableRight="@drawable/ic_key"
android:ems="10"
android:hint="@string/app_Password"
android:inputType="textPassword"
android:translationZ="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/button2" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginTop="200dp"
android:drawableRight="@drawable/ic_key"
android:ems="10"
android:hint="@string/app_Confirm_password"
android:inputType="textPassword"
android:translationZ="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/button2"
/>
</android.support.constraint.ConstraintLayout>
<Button
android:id="@+id/button"
android:layout_width="128dp"
android:layout_height="38dp"
android:layout_marginBottom="44dp"
android:layout_marginEnd="116dp"
android:layout_marginRight="116dp"
android:background="@drawable/signupbutton"
android:text="@string/app_singup"
android:textColor="@color/colorwhite"
android:translationZ="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</android.support.constraint.ConstraintLayout>
我的风格
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<dimen name="topRightRadius">65dp</dimen>
<dimen name="textSize">20dp</dimen>
<style name="first">
<item name="android:topRightRadius">@dimen/topRightRadius</item>
<!--<item name="android:radius">65dp</item>-->
<item name="android:background">@color/colorAccent</item>
</style>
<style name="Longin">
<item name="android:textColor">@color/colorwhiteblack</item>
<item name="android:textSize">20dp</item>
</style>
</resources>
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ali.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我的字符串
<resources>
<string name="app_name">My Doctor</string>
<string name="app_loging">Login</string>
<string name="app_singup">Sign up</string>
<string name="app_Email">Email</string>
<string name="app_Password">Password</string>
<string name="app_Confirm_password">Confirm password</string>
</resources>
我的颜色
<?xml version="1.0" encoding="utf-8"?> <resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorwhite">#ffffff</color>
<color name="colortoowhite">#efe9e9</color>
<color name="colorblack">#0d0c0c</color>
<color name="colorwhiteblack">#c1baba</color>
<color name="colorharaqua">#15c5e4</color>
<color name="coloraqua">#ed1fd3e7</color>
</resources>
我的应用程序结构我的应用程序结构如下我的应用程序结构如下
structure
第一
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape android:shape="rectangle">
<!--<corners android:topRightRadius="45dp"/>-->
<corners android:topLeftRadius="45dp"
android:topRightRadius="0.1dp"
android:bottomLeftRadius="45dp"
android:bottomRightRadius="0.1dp"/>
<gradient android:gradientRadius="45dp"
android:angle="-90" android:startColor="#5a92f0"
android:endColor="@color/colorAccent" />
</shape>
</item>
</selector>
注册前台背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape ="rectangle">
<corners android:radius="20dp"/>
<solid android:color="@color/colorwhite"/>
<stroke
android:color="@color/colortoowhite"
android:width="1dp"
/>
<!--<padding-->
<!--android:right="10dp"-->
<!--android:bottom="10dp"-->
<!--android:left="10dp"-->
<!--android:top="10dp"/>-->
</shape>
注册按钮
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="@color/colorharaqua"
android:endColor="@color/coloraqua"
android:angle="360"
/>
<corners android:topLeftRadius="105dp"
android:bottomLeftRadius="105dp"
android:topRightRadius="95dp"
android:bottomRightRadius="95dp"
/>
</shape>
它抱怨你的背景指针指向一个不可绘制的 id。
android:background="@drawable/signupbutton"
使用 drawable 目录中的这个名称显示您的 drawable。
此外,只是一个旁注,
您的样式 "first" 没有父项。您可能想尝试为您的样式分配一个按钮父级。比如
<style name="first" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">@color/Red</item>
<item name="android:textColor">@color/White</item>
</style>
这样您就可以绑定到主题的特定父主题,而不是让它保持打开状态,但这只是我的偏好。
您的可绘制对象看起来不错,但它们位于 v24 文件夹中,因此如果您在 24 之前的设备上启动它,它们将不可用。
通过设置相同的文件夹结构并使用 v23 模拟器,我能够重现您的崩溃。
嗨,每当我 运行 我的应用程序崩溃时,我检查过 Logcat 它给出了这个错误字符串
我的代码和我的应用程序的结构如下,我一直在寻找答案 并希望有人帮助我。
提前致谢
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}
这是我的 XML
<?xml version="1.0" encoding="utf-8"?> android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<!--tools:layout_editor_absoluteX="16dp"-->
<!--tools:layout_editor_absoluteY="81dp"-->
<android.support.constraint.ConstraintLayout
android:layout_width="135dp"
android:layout_height="203dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="60dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView_login"
style="@style/Longin"
android:layout_width="69dp"
android:layout_height="30dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:text="@string/app_loging"
android:translationZ="3dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.15" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="172dp"
android:layout_height="431dp"
android:layout_marginTop="64dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/backedbackground"
style="@style/first"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:background="@drawable/first"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView_signup"
style="@style/Longin"
android:layout_width="69dp"
android:layout_height="30dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:text="@string/app_singup"
android:textColor="@color/colorwhite"
android:translationZ="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.908"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="312dp"
android:layout_height="319dp"
android:layout_marginTop="124dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/signupfrontbackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="62dp"
android:layout_marginTop="24dp"
android:drawableRight="@drawable/ic_user_male_black_shape"
android:ems="10"
android:hint="User name"
android:inputType="textPersonName"
android:translationZ="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:drawableRight="@drawable/ic_envelope"
android:ems="10"
android:hint="@string/app_Email"
android:inputType="textEmailAddress"
android:translationZ="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.329" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="59dp"
android:layout_marginTop="140dp"
android:drawableRight="@drawable/ic_key"
android:ems="10"
android:hint="@string/app_Password"
android:inputType="textPassword"
android:translationZ="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/button2" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginTop="200dp"
android:drawableRight="@drawable/ic_key"
android:ems="10"
android:hint="@string/app_Confirm_password"
android:inputType="textPassword"
android:translationZ="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/button2"
/>
</android.support.constraint.ConstraintLayout>
<Button
android:id="@+id/button"
android:layout_width="128dp"
android:layout_height="38dp"
android:layout_marginBottom="44dp"
android:layout_marginEnd="116dp"
android:layout_marginRight="116dp"
android:background="@drawable/signupbutton"
android:text="@string/app_singup"
android:textColor="@color/colorwhite"
android:translationZ="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</android.support.constraint.ConstraintLayout>
我的风格
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<dimen name="topRightRadius">65dp</dimen>
<dimen name="textSize">20dp</dimen>
<style name="first">
<item name="android:topRightRadius">@dimen/topRightRadius</item>
<!--<item name="android:radius">65dp</item>-->
<item name="android:background">@color/colorAccent</item>
</style>
<style name="Longin">
<item name="android:textColor">@color/colorwhiteblack</item>
<item name="android:textSize">20dp</item>
</style>
</resources>
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ali.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我的字符串
<resources>
<string name="app_name">My Doctor</string>
<string name="app_loging">Login</string>
<string name="app_singup">Sign up</string>
<string name="app_Email">Email</string>
<string name="app_Password">Password</string>
<string name="app_Confirm_password">Confirm password</string>
</resources>
我的颜色
<?xml version="1.0" encoding="utf-8"?> <resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorwhite">#ffffff</color>
<color name="colortoowhite">#efe9e9</color>
<color name="colorblack">#0d0c0c</color>
<color name="colorwhiteblack">#c1baba</color>
<color name="colorharaqua">#15c5e4</color>
<color name="coloraqua">#ed1fd3e7</color>
</resources>
我的应用程序结构我的应用程序结构如下我的应用程序结构如下
structure
第一
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape android:shape="rectangle">
<!--<corners android:topRightRadius="45dp"/>-->
<corners android:topLeftRadius="45dp"
android:topRightRadius="0.1dp"
android:bottomLeftRadius="45dp"
android:bottomRightRadius="0.1dp"/>
<gradient android:gradientRadius="45dp"
android:angle="-90" android:startColor="#5a92f0"
android:endColor="@color/colorAccent" />
</shape>
</item>
</selector>
注册前台背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape ="rectangle">
<corners android:radius="20dp"/>
<solid android:color="@color/colorwhite"/>
<stroke
android:color="@color/colortoowhite"
android:width="1dp"
/>
<!--<padding-->
<!--android:right="10dp"-->
<!--android:bottom="10dp"-->
<!--android:left="10dp"-->
<!--android:top="10dp"/>-->
</shape>
注册按钮
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="@color/colorharaqua"
android:endColor="@color/coloraqua"
android:angle="360"
/>
<corners android:topLeftRadius="105dp"
android:bottomLeftRadius="105dp"
android:topRightRadius="95dp"
android:bottomRightRadius="95dp"
/>
</shape>
它抱怨你的背景指针指向一个不可绘制的 id。
android:background="@drawable/signupbutton"
使用 drawable 目录中的这个名称显示您的 drawable。
此外,只是一个旁注,
您的样式 "first" 没有父项。您可能想尝试为您的样式分配一个按钮父级。比如
<style name="first" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">@color/Red</item>
<item name="android:textColor">@color/White</item>
</style>
这样您就可以绑定到主题的特定父主题,而不是让它保持打开状态,但这只是我的偏好。
您的可绘制对象看起来不错,但它们位于 v24 文件夹中,因此如果您在 24 之前的设备上启动它,它们将不可用。 通过设置相同的文件夹结构并使用 v23 模拟器,我能够重现您的崩溃。