首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >android.view.InflateException:二进制XML文件第2行:二进制XML文件第2行:膨胀类android.widget.RelativeLayout时出错

android.view.InflateException:二进制XML文件第2行:二进制XML文件第2行:膨胀类android.widget.RelativeLayout时出错
EN

Stack Overflow用户
提问于 2018-06-03 02:09:30
回答 2查看 3.9K关注 0票数 1

我是一个android基础课程的初学者,我正在制作一个计分器应用程序,但当我用我的手机在android studio上运行它时,它给出了以下日志错误,并在我的设备上显示“不幸已停止”。

我非常担心这种情况,因为我是android开发的新手,并且遇到了这个问题,我将更加感谢能够解决这个问题的任何人,因为它已经在我的脑海中停留了下来

LogCat

06-02 22:38:55.991 30457-30457/? I/art: Late-enabling -Xcheck:jni
06-02 22:38:56.059 30457-30457/com.example.tasbeeh.tasbeehcounter W/System: ClassLoader referenced unknown path: /data/app/com.example.tasbeeh.tasbeehcounter-1/lib/arm
06-02 22:38:56.107 30457-30457/com.example.tasbeeh.tasbeehcounter W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
06-02 22:38:56.192 30457-30457/com.example.tasbeeh.tasbeehcounter W/ResourceType: Failure getting entry for 0x7f060054 (t=5 e=84) (error -75)
06-02 22:38:56.194 30457-30457/com.example.tasbeeh.tasbeehcounter D/AndroidRuntime: Shutting down VM
06-02 22:38:56.197 30457-30457/com.example.tasbeeh.tasbeehcounter E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.tasbeeh.tasbeehcounter, PID: 30457
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tasbeeh.tasbeehcounter/com.example.tasbeeh.tasbeehcounter.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5443)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
     Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
        at com.example.tasbeeh.tasbeehcounter.MainActivity.onCreate(MainActivity.java:16)
        at android.app.Activity.performCreate(Activity.java:6245)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5443) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
     Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
        at android.view.LayoutInflater.createView(LayoutInflater.java:645)
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
        at com.example.tasbeeh.tasbeehcounter.MainActivity.onCreate(MainActivity.java:16) 
        at android.app.Activity.performCreate(Activity.java:6245) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5443) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at android.view.LayoutInflater.createView(LayoutInflater.java:619)
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
        at com.example.tasbeeh.tasbeehcounter.MainActivity.onCreate(MainActivity.java:16) 
        at android.app.Activity.performCreate(Activity.java:6245) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5443) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
     Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.tasbeeh.tasbeehcounter:drawable/ground" (7f060054) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060054 a=-1 r=0x7f060054}
        at android.content.res.Resources.loadDrawableForCookie(Resources.java:2605)
        at android.content.res.Resources.loadDrawable(Resources.java:2543)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
        at android.view.View.<init>(View.java:3951)
        at android.view.ViewGroup.<init>(ViewGroup.java:573)
        at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
        at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
        at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
        at java.lang.reflect.Constructor.newInstance(Native Method) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
        at com.example.tasbeeh.tasbeehcounter.MainActivity.onCreate(MainActivity.java:16) 
        at android.app.Activity.performCreate(Activity.java:6245) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5443) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
06-02 22:38:58.350 30457-30457/com.example.tasbeeh.tasbeehcounter I/Process: Sending signal. PID: 30457 SIG: 9

Layout_xml文件

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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_height="match_parent"
    android:layout_width="match_parent"
    android:background="@drawable/ground"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="180dp"
        android:scaleType="centerCrop"
        android:src="@drawable/mosque" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:orientation="horizontal">

        <LinearLayout 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="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="Person 1"
                android:textColor="@color/colorPrimary"
                android:textSize="?android:textAppearanceLarge" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="Quran Read"
                android:textColor="@color/colorPrimary"
                android:textSize="20sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/quranView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="0"
                android:textColor="@android:color/black"
                android:textSize="30sp" />

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

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="2dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:onClick="addQuran1"
                    android:text="Add"
                    android:textColor="@android:color/white" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:onClick="lessQuran1"
                    android:text="Less"
                    android:textColor="@android:color/white" />

            </LinearLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="Durood Shareef"
                android:textColor="@android:color/black"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/duroodView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="0"
                android:textColor="@android:color/black"
                android:textSize="30sp" />

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

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="2dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:onClick="addDurood1"
                    android:text="Add"
                    android:textColor="@android:color/white" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:onClick="lessDurood1"
                    android:text="Less"
                    android:textColor="@android:color/white" />

            </LinearLayout>

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

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginTop="8dp"
                    android:background="@color/colorPrimary"
                    android:onClick="resetThis1"
                    android:text="Reset This"
                    android:textColor="@android:color/white" />


            </LinearLayout>

        </LinearLayout>

        <LinearLayout 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="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="Person 2"
                android:textColor="@color/colorPrimary"
                android:textSize="?android:textAppearanceLarge" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="Quran Read"
                android:textColor="@color/colorPrimary"
                android:textSize="20sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/quranView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="0"
                android:textColor="@android:color/black"
                android:textSize="30sp" />

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

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="2dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:onClick="addQuran2"
                    android:text="Add"
                    android:textColor="@android:color/white" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:onClick="lessQuran2"
                    android:text="Less"
                    android:textColor="@android:color/white" />

            </LinearLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="Durood Shareef"
                android:textColor="@android:color/black"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/duroodView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:gravity="center_horizontal"
                android:text="0"
                android:textColor="@android:color/black"
                android:textSize="30sp" />

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

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="2dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:onClick="addDurood2"
                    android:text="Add"
                    android:textColor="@android:color/white" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="1"
                    android:background="@color/colorPrimary"
                    android:onClick="lessDurood2"
                    android:text="Less"
                    android:textColor="@android:color/white" />

            </LinearLayout>

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

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginTop="8dp"
                    android:background="@color/colorPrimary"
                    android:onClick="resetThis2"
                    android:text="Reset This"
                    android:textColor="@android:color/white" />


            </LinearLayout>

        </LinearLayout>

    </LinearLayout>


</RelativeLayout>

MainActivity

package com.example.tasbeeh.tasbeehcounter;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    int quran = 0;
    int durood = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void addQuran1 (View view){
        quran = quran + 1;
        displayQuran1(quran);
    }

    public void lessQuran1 (View view){
        quran = quran - 1;
        displayQuran1(quran);
    }

    public void addDurood1 (View view){
        durood = durood + 1;
        displayDurood1(durood);
    }

    public void lessDurood1 (View view){
        durood = durood - 1;
        displayDurood1(durood);
    }

    public void addQuran2 (View view){
        quran = quran + 1;
        displayQuran2(quran);
    }

    public void lessQuran2 (View view){
        quran = quran - 1;
        displayQuran2(quran);
    }

    public void addDurood2 (View view){
        durood = durood + 1;
        displayDurood2(durood);
    }

    public void lessDurood2 (View view){
        durood = durood - 1;
        displayDurood2(durood);
    }

    public void resetThis1 (View view) {
        quran = 0;
        durood = 0;
        displayQuran1(quran);
        displayDurood1(durood);
    }

    public void resetThis2 (View view) {
        quran = 0;
        durood = 0;
        displayQuran2(quran);
        displayDurood2(durood);
    }






    private void displayQuran1 (int number){
        TextView quran1displayview = (TextView) findViewById(R.id.quranView1);
        quran1displayview.setText("" + number);
    }

    private void displayDurood1 (int number){
        TextView durood1displayview = (TextView) findViewById(R.id.duroodView1);
        durood1displayview.setText("" + number);
    }

    private void displayQuran2 (int number){
        TextView quran2displayview = (TextView) findViewById(R.id.quranView2);
        quran2displayview.setText("" + number);
    }

    private void displayDurood2 (int number){
        TextView durood2displayview = (TextView) findViewById(R.id.duroodView2);
        durood2displayview.setText("" + number);
    }
}

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-03 02:25:00

如果您看到异常的根本原因,则实际问题是

android.content.res.Resources$NotFoundException: Resource "com.example.tasbeeh.tasbeehcounter:drawable/ground" (7f060054) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060054 a=-1 r=0x7f060054}

在您的layout.xml文件中,您已经为根RelativeLayout使用了背景。

<RelativeLayout 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_height="match_parent"
    android:layout_width="match_parent"
    android:background="@drawable/ground" <-- Here
    tools:context=".MainActivity">

确保已将名为ground的可绘制文件(文件或xml)添加到可绘制或可绘制-* (mdpi、hdmi、xhdpi、xxhdpi和xxxhdpi)文件夹中。

提示:尝试使用矢量绘图文件,而不是静态png文件。更多信息请访问:https://developer.android.com/guide/topics/graphics/vector-drawable-resources

票数 1
EN

Stack Overflow用户

发布于 2019-07-16 02:31:03

可绘制的图像可能在v24中,删除此图像并将其放置在没有v24的地方(简单)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50659783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档