android.view.InflateException:二进制XML文件行#2:二进制XML文件行#2:错误膨胀类android.widget.RelativeLayout

时间:2018-06-02 18:09:30

标签: java android android-linearlayout

我是android基础课程的初学者,我正在制作一个得分管理器应用程序,但当我在Android工作室使用我的手机运行时,它会给出以下日志错误以及显示"不幸的是已停止& #34;在我的设备上。

我非常担心这种情况,因为我是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
&#13;
&#13;
&#13;

Layout_xml文件

&#13;
&#13;
<?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>
&#13;
&#13;
&#13;

MainActivity

&#13;
&#13;
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);
    }
}
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

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

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">

确保在drawable或drawable - ****(mdpi,hdmi,xhdpi,xxhdpi和xxxhdpi)文件夹中添加了名为ground的drawable(文件或xml)。

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

答案 1 :(得分:0)

可绘制图像可能位于v24中,请将其删除,然后将其放置为不包含v24(简单)。