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

如何修复此错误?Android.View.InflateException:二进制XML文件行#11

邵鸿福
2023-03-14

你好所有我的activity不会启动,因为一些原因,我有麻烦弄清楚,这是一个简单的应用程序,它启动和显示这个布局,但我不断得到错误,每次我启动它,我不知道为什么

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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".HomeActivity"
    tools:showIn="@layout/app_bar_home">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/back">

        <ImageView
            android:id="@+id/btnTraining"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_centerInParent="true"
            android:src="@drawable/play" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:orientation="horizontal">

                <info.hoang8f.widget.FButton
                    android:id="@+id/btnExercises"
                    android:text="Exercises"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="4dp"
                    android:layout_weight="1"
                    android:textColor="@color/white"
                    app:buttonColor="@color/colorPrimary"
                    app:shadowColor="@color/colorPrimaryDark"
                    app:shadowEnabled="true"
                    app:cornerRadius="2dp"
                    app:shadowHeight="2dp" />

                <info.hoang8f.widget.FButton
                    android:id="@+id/btnSetting"
                    android:text="Setting"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginRight="8dp"
                    android:layout_weight="1"
                    android:textColor="@color/white"
                    app:buttonColor="@color/colorPrimary"
                    app:shadowColor="@color/colorPrimaryDark"
                    app:shadowEnabled="true"
                    app:cornerRadius="2dp"
                    app:shadowHeight="2dp" />

            </LinearLayout>

            <info.hoang8f.widget.FButton
                android:id="@+id/btnCalender"
                android:text="Calender"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="4dp"
                android:layout_marginTop="8dp"
                android:textColor="@color/white"
                app:buttonColor="@color/colorPrimary"
                app:shadowColor="@color/colorPrimaryDark"
                app:shadowEnabled="true"
                app:cornerRadius="0dp"
                app:shadowHeight="2dp" />

        </LinearLayout>
    </RelativeLayout>

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

Java电码

    package com.example.kishorsinh.yogaapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

public class HomeActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    Button btnExercises,btnSetting,btnCalender;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);



        btnExercises =(Button)findViewById(R.id.btnExercises);
        btnExercises.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(HomeActivity.this,ListExercises.class);
                startActivity(intent);
            }
        });


    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home_activity, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        //if (id == R.id.action_settings) {
            //return true;
       // }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_instructions) {
            // Handle the camera action
        } else if (id == R.id.nav_benefits) {

        }else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_about) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

分级

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.kishorsinh.yogaapp"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    //Library
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'info.hoang8f:fbutton:1.0.5'


}

Gradle版本3.1.3

错误

java.lang.RuntimeException:无法启动activity组件Info{com.example.kishorsinh.yogaapp/com.example.kishorsinh.yogaapp.HomeActivity}:Android.View.InflateException:二进制XML文件行#11:二进制XML文件行#36:在Android.app.activitythread.PerformLaunchActivity(ActivityThread.java:2984)在Android.app.activityThread.HandleLaunchActivity(ActivityThread.java:3045)在文件行#36:膨胀类Info.Hoang8f.Widget.F Button时出错,原因是:Android.View.InflateException:二进制XML文件行#36:膨胀类Info.Hoang8f.Widget.F Button时出错,原因是:java.lang.Reflect.Constructor.NewInstance0(原生方法)在java.lang.Reflect.Constructor.NewInstance0(原生方法)在Android.View.LayoutInflater.CreateView(LayoutInflater.CreateView(ndroid.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:828)在Android.view.LayoutInflater.ParseInclude(LayoutInflater.Java:1011)在Android.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:861)在Android.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:828)在A:26)在Android.app.Activity.PerformCreate(Activity.java:6956)在Android.app.Instrumentation.CallActivityCreate(Instrumentation.java:1126)在Android.app.ActivityThread.PerformLaunchActivity(ActivityThread.java:2927)在Android.app.ActivityThread.HandleLaunchActivity(ActivityThread.java:3045)在Android.app.ActivityThread.-Wrap14(ActivityThread.java)在Android.app.ActivityThread$H.ton.java:116)在info.hoang8f.widget.fbutton。(fbutton.java:52)...37更多

共有3个答案

狄新立
2023-03-14

您的color.xml文件可能有问题

从错误日志中

原因:java.lang.UnsupportedOperationException:无法将索引%1处的值转换为颜色:在Android.Content.Res.TypedArray.GetColor(TypedArray.java:480)处的Type=0x5

一开始,你的颜色值好像是错的

尤祖鹤
2023-03-14

删除此

实现“info.hoang8f:fbutton:1.0.5”

<info.hoang8f.widget.FButton
            android:id="@+id/btnCalender"
            android:text="Calender"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="4dp"
            android:layout_marginTop="8dp"
            android:textColor="@color/white"
            app:buttonColor="@color/colorPrimary"
            app:shadowColor="@color/colorPrimaryDark"
            app:shadowEnabled="true"
            app:cornerRadius="0dp"
            app:shadowHeight="2dp" />
景河
2023-03-14

可能是您没有在应用程序gradle中添加以下依赖项:compile'info.hoang8f:fbutton:1.0.5'

 类似资料: