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

时间:2017-06-30 18:59:53

标签: java android android-multidex

我正在开发一个应用程序,当我运行时在android 6.0.1上完美运行但是当我在android 4.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) 

修改 activity_product.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>

content_product.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移动设备上崩溃,因为它在模拟器中运行,而其他设备运行相同的版本。

提前致谢。

1 个答案:

答案 0 :(得分:0)

由于drawableLeft和drawableStart添加到EditText而导致崩溃。显然4.4以下的android有该属性的问题。您可以为不同的版本使用两个xml文件,也可以使用EditText旁边的ImageView来显示您的drawable。请注意,您的代码适用于任何大于4.4的设备