首页 > 解决方案 > android.view.InflateException:错误膨胀类按钮

问题描述

我的应用程序出现问题。当我按下一个启动新活动的按钮(应用程序的菜单)时,我遇到了 java.lang.RuntimeException: Error inflating class Button

有人能解释一下这个例外是什么吗?

这是菜单活动的 XML

<android.support.v7.widget.Toolbar
    android:id="@+id/Toolbar"
    android:layout_width="match_parent"
    android:layout_height="91dp"
    android:background="@color/colorPrimary"
    android:elevation="4dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"     tools:targetApi="lollipop" />

<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="441dp"
    android:layout_height="726dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent">


    <LinearLayout
        android:id="@+id/linearlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/background_light"
        android:orientation="vertical">


        <Button
            android:id="@+id/saludos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/saludos"
            android:paddingTop="50dp"
            android:paddingBottom="50dp"
            android:text="@string/greetings_n_saludos"
            android:textColor="@android:color/background_dark"
            tools:targetApi="lollipop" />

        <Button
            android:id="@+id/presentaciones"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/presentaciones"
            android:text="@string/presentaciones"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/despedidas"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/despedidas"
            android:text="@string/despedidas"
            android:textColor="@android:color/white" />

        <Button
            android:id="@+id/school"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="50dp"
            android:background="@drawable/school"
            android:text="@string/school_colegio"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/numbers"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:layout_weight="1"
            android:background="@drawable/numbers"
            android:text="@string/numbers_n_meros"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/colors"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/colors"
            android:text="@string/colors_colores"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/family"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/family"
            android:text="@string/family_familia"
            android:textColor="@android:color/black" />

        <Button
            android:id="@+id/food"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/food"
            android:text="@string/food_comida"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/verbtobe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="50dp"
            android:background="@drawable/verbtobe"
            android:text="@string/verb_to_be"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/havegot"
            android:layout_width="143dp"
            android:layout_height="121dp"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/havegot"
            android:text="@string/to_have"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/verbs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/verbs"
            android:text="@string/verbs_n_verbos"
            android:textColor="@android:color/background_light" />


        <Button
            android:id="@+id/presentsimple"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/presentsimple"
            android:text="@string/present_simple"
            android:textColor="@android:color/background_dark"
            tools:text="@string/present_simple" />

        <Button
            android:id="@+id/presentcontinuous"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="50dp"
            android:background="@drawable/presentcontinuous"
            android:text="@string/present_continuous"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/pastsimple"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/pastsimple"
            android:text="@string/past_simple"
            android:textColor="@android:color/background_dark" />

        <Button
            android:id="@+id/pastcontinuous"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/pastcontinuous"
            android:text="@string/past_continuous"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/presentperfect"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/presentperfect"
            android:text="@string/past_continuous"
            android:textColor="@android:color/background_dark" />

        <Button
            android:id="@+id/presentperfectcontinuous"
            android:layout_width="wrap_content"
            android:layout_height="161dp"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/presentcontinuous"
            android:text="@string/past_continuous"
            android:textColor="@android:color/background_dark" />

        <Button
            android:id="@+id/pastperfect"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="50dp"
            android:background="@drawable/presentcontinuous"
            android:text="@string/past_continuous"
            android:textColor="@android:color/background_dark" />

        <Button
            android:id="@+id/pastperfectcontinuous"
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/pastperfectcontinuous"
            android:text="@string/past_continuous"
            android:textColor="@android:color/background_dark" />

        <Button
            android:id="@+id/thereisthereare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/thereisthereare"
            android:text="@string/there_is_there_are"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/nouns"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/nouns"
            android:text="@string/nouns_sustantivos"
            android:textColor="@android:color/background_light"
            tools:text="nouns sustantivos" />

        <Button
            android:id="@+id/adverbs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/adverbs"
            android:text="@string/adverbs_los_adverbios"
            android:textColor="@android:color/background_light"
            tools:text="@string/adverbs_los_adverbios" />

        <Button
            android:id="@+id/adjetivos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/adjectives"
            android:text="@string/adjectives_adjetivos"
            android:textColor="@android:color/black"
            tools:text="@string/adjectives_adjetivos" />

        <Button
            android:id="@+id/holidays"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/holidays"
            android:text="@string/holidays_vacaciones"
            android:textColor="@drawable/holidays"
            tools:text="@string/holidays_vacaciones" />

        <Button
            android:id="@+id/shopping"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/shopping"
            android:text="@string/we_go_shopping_vamos_de_compras"
            android:textColor="@android:color/background_light"
            tools:text="we go shopping!" />

        <Button
            android:id="@+id/quiz"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="50dp"
            android:layout_marginBottom="50dp"
            android:background="@android:color/background_light"
            android:text="@string/quiz"
            android:textColor="@android:color/background_dark"
            tools:text="nouns sustantivos" />

        <Button
            android:id="@+id/people"
            android:layout_width="143dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="50dp"
            android:background="@drawable/describing"
                android:text="@string/describing_people_describiendo_gente"
            android:textColor="@android:color/background_dark"
            tools:text="Describing People - Describiendo Gente" />

        <Button
            android:id="@+id/works"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:layout_marginBottom="100dp"
            android:background="@drawable/works"
            android:text="@string/works_n_trabajos"
            android:textColor="@android:color/background_light" />

    </LinearLayout>
</ScrollView>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

这是Logcat

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.flixarts.ar.englishnow, PID: 10925
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.flixarts.ar.englishnow/com.flixarts.ar.englishnow.menuscreen}: android.view.InflateException: Binary XML file line #298: Binary XML file line #298: Error inflating class Button
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: android.view.InflateException: Binary XML file line #298: Binary XML file line #298: Error inflating class Button
 Caused by: android.view.InflateException: Binary XML file line #298: Error inflating class Button
 Caused by: android.content.res.Resources$NotFoundException: Can't find ColorStateList from drawable resource ID #0x7f070075
    at android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:1042)
    at android.content.res.Resources.loadColorStateList(Resources.java:1041)
    at android.content.res.TypedArray.getColorStateList(TypedArray.java:549)
    at android.widget.TextView.readTextAppearance(TextView.java:3542)
    at android.widget.TextView.<init>(TextView.java:959)
    at android.widget.Button.<init>(Button.java:166)
    at android.widget.Button.<init>(Button.java:141)
    at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:70)
    at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66)
    at android.support.v7.app.AppCompatViewInflater.createButton(AppCompatViewInflater.java:186)
    at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
    at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1035)
    at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at com.flixarts.ar.englishnow.menuscreen.onCreate(menuscreen.java:45)
    at android.app.Activity.performCreate(Activity.java:7136)
    at android.app.Activity.performCreate(Activity.java:7127)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
E/AndroidRuntime:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.

我不知道发生了什么,我已经尽可能简洁地编写代码并且有效,但现在我有这个异常

标签: android

解决方案


原因:android.content.res.Resources$NotFoundException:无法从可绘制资源 ID 中找到 ColorStateList。

这表明运行时环境无法找到特定资源。

大概是吧@drawable/holidays。检查这是否是您项目的一部分。


推荐阅读