当前位置: 首页 > 知识库问答 >
问题:

由于类膨胀错误,应用程序崩溃

邵研
2023-03-14

我正在开发一个应用程序,当我在Android6.0.1上运行时,它运行得非常好,但当我在Android4.4.2上运行时,该应用程序突然崩溃,并显示“类膨胀错误”。请帮帮我。我搜索并对我的代码做了很多修改,但没有任何帮助。一些解决方案包括在依赖项中使用multidex,以及通过stackoverflow使用少数其他解决方案。

app.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {

        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.google.firebase:firebase-crash:10.0.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:design:26.0.0-alpha1'
    compile 'com.android.support:cardview-v7:26.0.0-alpha1'
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
}

**logcat**

FATAL EXCEPTION: main
                                                                    Process: madevina.saveawatt, PID: 25177
                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{madevina.saveawatt/madevina.saveawatt.ProductActivity}: android.view.InflateException: Binary XML file line #35: Error inflating class EditText
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
                                                                        at android.app.ActivityThread.access$800(ActivityThread.java:156)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:157)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5872)
                                                                        at java.lang.reflect.Method.invokeNative(Native Method)
                                                                        at java.lang.reflect.Method.invoke(Method.java:515)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
                                                                        at dalvik.system.NativeStart.main(Native Method)
                                                                     Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class EditText
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                        at madevina.saveawatt.ProductActivity.onCreate(ProductActivity.java:60)
                                                                        at android.app.Activity.performCreate(Activity.java:5312)
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653) 
                                                                        at android.app.ActivityThread.access$800(ActivityThread.java:156) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:157) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5872) 
                                                                        at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                        at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674) 
                                                                        at dalvik.system.NativeStart.main(Native Method) 
                                                                     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/req_qty.xml from drawable resource ID #0x7f02009e
                                                                        at android.content.res.Resources.loadDrawable(Resources.java:2134)
                                                                        at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                        at android.widget.TextView.<init>(TextView.java:859)
                                                                        at android.widget.EditText.<init>(EditText.java:60)
                                                                        at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:62)
                                                                        at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:58)
                                                                        at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1026)
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1083)
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839) 
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289) 
                                                                        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                                        at madevina.saveawatt.ProductActivity.onCreate(ProductActivity.java:60) 
                                                                        at android.app.Activity.performCreate(Activity.java:5312) 
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111) 
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552) 
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653) 
                                                                        at android.app.ActivityThread.access$800(ActivityThread.java:156) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:157) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5872) 
                                                                        at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                        at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674) 
                                                                        at dalvik.system.NativeStart.main(Native Method) 
                                                                     Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
                                                                        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
                                                                        at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
                                                                        at android.content.res.Resources.loadDrawable(Resources.java:2130)
                                                                        at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 
                                                                        at android.widget.TextView.<init>(TextView.java:859) 
                                                                        at android.widget.EditText.<init>(EditText.java:60) 
                                                                        at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:62) 
                                                                        at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:58) 
                                                                        at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112) 
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1026) 
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1083) 
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684) 
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839) 
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289) 
                                                                        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                                        at madevina.saveawatt.ProductActivity.onCreate(ProductActivity.java:60) 
                                                                        at android.app.Activity.performCreate(Activity.java:5312) 
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111) 
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552) 
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653) 
                                                                        at android.app.ActivityThread.access$800(ActivityThread.java:156) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:157) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5872) 
                                                                        at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                        at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674) 
                                                                        at dalvik.system.NativeStart.main(Native Method) 

编辑产品的活动。xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="madevina.saveawatt.ProductActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_product" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@drawable/ic_send" />

</android.support.design.widget.CoordinatorLayout>

内容与产品。xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginEnd="8dp">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Select product "
            android:textColor="@color/colorAccent" />

        <Spinner
            android:id="@+id/spinner_product"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:spinnerMode="dialog" />

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/p_qty"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableStart="@drawable/req_qty"
                android:drawableLeft="@drawable/req_qty"
                android:hint="Quantity"
                android:inputType="number" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/p_cap"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/req_cap"
                android:hint="Capacity"
                android:inputType="number" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/p_contactname"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/req_personred"
                android:hint="Contact name "
                android:inputType="textCapWords" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/p_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/req_email"
                android:hint="E-Mail"
                android:inputType="textEmailAddress" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/p_cname"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/req_company"
                android:hint="Company name "
                android:inputType="textPersonName" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/p_mobile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/req_mobile"
                android:hint="Mobile"
                android:inputType="phone" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp">

            <EditText
                android:id="@+id/p_addr"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/req_home"
                android:hint="Address"
                android:inputType="textMultiLine" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Select city "
                android:textColor="@color/colorAccent" />
        </android.support.design.widget.TextInputLayout>

        <Spinner
            android:id="@+id/pr_sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:spinnerMode="dropdown" />
    </LinearLayout>

</LinearLayout>

该应用程序也在拥有android 6.0.1的LeEco mobile上崩溃,因为它在模拟器中运行,并且很少有其他设备运行相同的版本。

提前感谢。

共有1个答案

司寇旺
2023-03-14

它的崩溃是因为添加到EditText中的可绘制的左和可绘制的开始。显然低于4.4的Android系统对该属性有问题。您可以为不同的版本使用两个xml文件,也可以使用EditText旁边的ImageView来显示您的绘图。请注意,您的代码将在任何大于4.4的设备上工作

 类似资料:
  • 问题内容: 我正在尝试创建一个扩展的自定义视图。这是我的班级定义文件 : 这是在我的ghostviewscreen.xml中: 现在,我在活动中进行了: 当被调用时,抛出一个异常: 谁能告诉我为什么会出现此错误?谢谢。 问题答案: 我想我弄清楚了为什么这没用。当我应该为两个参数“ Context,AttributeSet”的情况提供构造函数时,我只为一个参数“ context”的情况提供了构造函数

  • 我想创建一个应用程序,其中NavigationView和Bottom Navigation可以互相工作,但在输出中,我在“Run”中得到了下一个字符串。 .

  • 问题内容: 您好,我是android dev和admob的新手。我正在尝试制作一个带有按钮,几个页面和底部的admob的简单测试应用程序。一切正常,直到我尝试实施admob。这是我的代码: HelloAndroid.java: main.xml: 您好android清单: logcat输出: 我正在使用GoogleAdMobAdsSdkAndroid-6.0.0。再次,我对此非常陌生,我尝试在多个

  • 问题内容: 错误日志: 10-26 12:22:33.144 26926-26926 /?E / AndroidRuntime:致命例外:主进程:ksmk.sahip.com.ecom,PID:26926 java.lang.RuntimeException:无法启动活动ComponentInfo {ksmk.sahip.com.ecom / ksmk.sahip.com.ecom.MainAct

  • 主要活动: } 片段类 错误:java.lang.runtimeException:无法启动活动ComponentInfo{com.darkweb.android.chroma2018/com.darkweb.android.chroma2018.mainactivity}:Android.view.filflateException:二进制XML文件行#0:错误inflating类在Androi

  • 问题内容: 尝试运行我的应用程序时,我意外地遇到了以下错误: 下面是日志猫: 以下是Java代码: 下面是布局代码: 提前致谢 问题答案: 我通过在app / build.gradle上添加更新的cardview和appcompat解决了这一问题 然后重建项目