简体   繁体   English

应用程式因类膨胀错误而当机

[英]App crash due to class inflate error

i am working on an app which when i run is working perfectly on android 6.0.1 but when i run it on android 4.4.2 the app suddenly crashes saying class inflate error. 我正在开发一个应用程序,当我在android 6.0.1上运行时,它可以完美运行,但是当我在android 4.4.2上运行时,该应用程序突然崩溃,提示类膨胀错误。 pleas help me. 请帮我。 i searched and made many modifications to my code but nothing helped me. 我搜索并修改了我的代码,但没有任何帮助。 Some solutions include using multidex in dependencies and few other solutions through stackoverflow. 一些解决方案包括在依赖项中使用multidex,以及通过stackoverflow进行其他一些解决方案。

app.gradle 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) 

EDIT activity_product.xml 编辑 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 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>

the app also crashed on LeEco mobile having android 6.0.1 where as it is running in emulators and few other devices running the same version. 该应用程序在装有Android 6.0.1的LeEco移动设备上也崩溃了,因为它正在模拟器中运行,而其他几个运行相同版本的设备也正在运行。

Thanks in advance. 提前致谢。

Its crashing because of the drawableLeft and drawableStart added to the EditText. 由于将drawableLeft和drawableStart添加到EditText而使其崩溃。 Apparently android below 4.4 have an issue with that property. 显然低于4.4的android对该属性存在问题。 You can either use two xml files for the different version or use and ImageView next to the EditText to display your drawable. 您可以将两个xml文件用于不同的版本,也可以使用EditText旁边的ImageView来显示可绘制对象。 Note your code will work on any device greater than 4.4 请注意,您的代码将在大于4.4的任何设备上运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何删除由于内存不足错误而导致的膨胀异常 - How to remove inflate exceptions ocurring due to out of memory error 使用Parse.enableLocalDatastore(this)处理扩展应用程序的单独类时,应用程序未崩溃 - App didn't crash due to Parse.enableLocalDatastore(this) while working with a separate class that extends Application 由于服务类错误,Spring Boot应用无法启动 - Spring boot app not starting due to Service Class Error 导致类android.widget.GridLayout应用崩溃的错误 - Error inflating class android.widget.GridLayout app crash 应用程序崩溃但代码中没有错误 - App Crash but there is no error in the code 编码时没有错误显示,但在我登录主页后会崩溃。 logcat 显示错误在 inflate 行中 - There is no error show in coding but it will crash after I login to my home page. The logcat shows that the error is in the inflate line 膨胀异常二进制XML文件行#膨胀类TextView时出错 - Inflate Exception Binary XML file line # Error inflating class TextView 扩充片段类别 - Inflate a fragment class 由于 android.content.res.Resources$NotFoundException,应用程序崩溃: - app crash due to android.content.res.Resources$NotFoundException: 导致应用崩溃的未知错误 - unknown error causing the app to crash
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM