android.view.InflateException: Binary XML 文件行 #2: Binary XML



我是安卓基础课程的初学者,我正在制作一个记分员应用程序,但是当我在安卓工作室用手机运行它时,它给出了以下日志错误,并显示"不幸的是已停止"在我的设备上。

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

日志猫

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>

主活动

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);
}
}

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

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}

在您的布局.xml文件中,您已经为根相对布局使用了背景。

<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

可绘制图像可能在 v24 中,删除它并将其放在没有 v24(简单(的情况下。

相关内容

最新更新