android.view.InflateException:总是错误

Posted

技术标签:

【中文标题】android.view.InflateException:总是错误【英文标题】:android.view.InflateException: always error 【发布时间】:2021-06-05 14:10:15 【问题描述】:

我有无法解释的令人沮丧的错误。这是我的主要活动布局文件:

build.gradle

apply plugin: 'com.android.application'

android 
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig 
        applicationId "com.asser.egycab"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 5
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    
    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        
    
    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    



dependencies 
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.code.findbugs:jsr305:3.0.2'

    //Horizontal date picker
    implementation 'joda-time:joda-time:2.9.7'

    //Timeline
//    implementation 'com.github.vipulasri:timelineview:1.0.6'

    //Calendar
    implementation 'com.applandeo:material-calendar-view:1.4.0'

    //Paypal
    implementation 'com.paypal.sdk:paypal-android-sdk:2.16.0'

    //Credit Card
    implementation 'com.craftman.cardform:cardform:0.0.2'

    //Job Scheduler
    implementation 'com.github.simplymadeapps:QuickPeriodicJobScheduler:-SNAPSHOT'

    implementation 'com.github.jd-alexander:library:1.1.0'

    //Volley
    implementation 'com.mcxiaoke.volley:library-aar:1.0.1'

    //Google Map
    implementation 'com.google.android.gms:play-services-location:18.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation('com.google.android.libraries.places:places:2.4.0') 
        exclude module: 'volley'
    

    //Glide
    implementation 'com.github.bumptech.glide:glide:4.12.0'

    //Place Picker
    implementation 'com.sucho:placepicker:0.1.8'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31'

    //Firebase
    implementation 'com.google.android.gms:play-services-auth:19.0.0'
    implementation 'com.google.firebase:firebase-core:18.0.2'
    implementation 'com.google.firebase:firebase-messaging:21.0.1'

    //Retrofit
    implementation('com.squareup.retrofit2:retrofit:2.9.0') 
        // exclude Retrofit’s OkHttp peer-dependency module and define your own module import
        exclude module: 'okhttp'
    
    implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2'
    implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    //Braintree
    implementation 'com.braintreepayments.api:drop-in:5.1.0'


// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

rootProject.allprojects 
    repositories 
        maven 
            url  "https://cardinalcommerce.bintray.com/android"
            credentials 
                username 'braintree-team-sdk@cardinalcommerce'
                password '220cc9476025679c4e5c843666c27d97cfb0f951'
            
        
    

错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.asser.egycab, PID: 12254
    android.view.InflateException: Binary XML file line #175 in com.asser.egycab:layout/fragment_bottom_sheet_booking: Binary XML file line #175 in com.asser.egycab:layout/fragment_bottom_sheet_booking: Error inflating class <unknown>
    Caused by: android.view.InflateException: Binary XML file line #175 in com.asser.egycab:layout/fragment_bottom_sheet_booking: Error inflating class <unknown>
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:855)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1012)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:963)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1142)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1103)
        at com.asser.egycab.fragment.customer.BottomSheetFragmentBooking.onCreateView(BottomSheetFragmentBooking.java:127) 

我不知道这里的真正错误 android.view.InflateException: 二进制 XML 文件行 #175

android.view.InflateException: Binary XML file line #175 in com.asser.egycab:layout/fragment_bottom_sheet_booking: Binary XML file line #175 in com.asser

第 175 行:

<com.google.android.material.textfield.TextInputLayout
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:id="@+id/intput_layout_place"
    android:layout_
    android:layout_
    android:theme="@style/TextLabel">

    <EditText
        android:drawableTint="@color/colorLogoBlack"
        android:drawableEnd="@drawable/ic_location_pin_"
        android:hint="@string/specify_exactly_your_location"
        android:textSize="16sp"
        android:id="@+id/input_place"
        android:layout_
        android:layout_
        android:inputType="textPersonName"
        android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:id="@+id/intput_layout_people_number"
    android:layout_
    android:layout_
    android:theme="@style/TextLabel">

    <EditText
        android:drawableTint="@color/colorLogoBlack"
        android:drawableEnd="@drawable/ic_team"
        android:maxLength="2"
        android:hint="@string/number_of_people"
        android:textSize="16sp"
        android:id="@+id/people_number"
        android:layout_
        android:layout_
        android:inputType="number"
        android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>

第 127 行:

View rootView = inflater.inflate(R.layout.fragment_bottom_sheet_booking, container, false);

那么如何解决这个错误,我在这里和谷歌上搜索了很多,但没有运气!

【问题讨论】:

请显示 build.gradle (app) 文件,或者请确认您在布局 fragment_bottom_sheet_booking 的第 175 行所写的内容 我添加了 build.gradle (app) 完整代码和第 175 行: 【参考方案1】:

终于解决了

通过更改&lt;style name="TextLabel" parent="TextAppearance.AppCompat"&gt;

&lt;style name="TextLabel" parent="Widget.MaterialComponents.TextInputLayout.FilledBox"&gt;

【讨论】:

以上是关于android.view.InflateException:总是错误的主要内容,如果未能解决你的问题,请参考以下文章