在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)错误膨胀类Button

时间:2017-11-11 06:21:51

标签: android xml appcompatactivity

当我尝试在某些设备上运行我的应用程序时(如Redmi Note 4)。随着LogCat错误,应用程序突然关闭。但它在安装了nougat 7.1的AVD上运行良好。帮帮我这个,我是android的初学者,无法理解造成这个问题的原因......

11 - 11 10: 31: 20.108 29463 - 29463 / ? I / art : Late - enabling - Xcheck: jni
11 - 11 10: 31: 20.129 29463 - 29463 / com.service.google.acessibility D / TidaProvider: TidaProvider()
11 - 11 10: 31: 20.151 29463 - 29463 / com.service.google.acessibility W / System: ClassLoader referenced unknown path: /data/app / com.service.google.acessibility - 1 / lib / arm64
11 - 11 10: 31: 20.176 29463 - 29463 / com.service.google.acessibility 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
11 - 11 10: 31: 20.201 29463 - 29463 / com.service.google.acessibility V / BoostFramework: mAcquireFunc method = public int com.qualcomm.qti.Performance.perfLockAcquire(int, int[])
11 - 11 10: 31: 20.201 29463 - 29463 / com.service.google.acessibility V / BoostFramework: mReleaseFunc method = public int com.qualcomm.qti.Performance.perfLockRelease()
11 - 11 10: 31: 20.201 29463 - 29463 / com.service.google.acessibility V / BoostFramework: mAcquireTouchFunc method = public int com.qualcomm.qti.Performance.perfLockAcquireTouch(android.view.MotionEvent, android.util.DisplayMetrics, int, int[])
11 - 11 10: 31: 20.202 29463 - 29463 / com.service.google.acessibility V / BoostFramework: mIOPStart method = public int com.qualcomm.qti.Performance.perfIOPrefetchStart(int, java.lang.String)
11 - 11 10: 31: 20.202 29463 - 29463 / com.service.google.acessibility V / BoostFramework: mIOPStop method = public int com.qualcomm.qti.Performance.perfIOPrefetchStop()
11 - 11 10: 31: 20.204 29463 - 29463 / com.service.google.acessibility V / BoostFramework: BoostFramework(): mPerf = com.qualcomm.qti.Performance@ be04472
11 - 11 10: 31: 20.204 29463 - 29463 / com.service.google.acessibility V / BoostFramework: BoostFramework(): mPerf = com.qualcomm.qti.Performance@ 58410c3
11 - 11 10: 31: 20.238 29463 - 29463 / com.service.google.acessibility W / ResourceType: Failure getting entry
for 0x7f060054(t = 5 e = 84)(error - 75)
11 - 11 10: 31: 20.238 29463 - 29463 / com.service.google.acessibility D / AndroidRuntime: Shutting down VM
11 - 11 10: 31: 20.239 29463 - 29463 / ? E / AndroidRuntime : FATAL EXCEPTION: main
Process: com.service.google.acessibility,
PID: 29463
java.lang.RuntimeException: Unable to start activity ComponentInfo {
    com.service.google.acessibility / com.service.google.acessibility.MainActivity
}: android.view.InflateException: Binary XML file line #0: Binary XML file line # 0: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2423)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2483)
at android.app.ActivityThread.access$900(ActivityThread.java: 153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1349)
at android.os.Handler.dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper.java: 148)
at android.app.ActivityThread.main(ActivityThread.java: 5438)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 628)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line # 0: Error inflating class Button
at android.view.LayoutInflater.inflate(LayoutInflater.java: 543)
at android.view.LayoutInflater.inflate(LayoutInflater.java: 427)
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.service.google.acessibility.MainActivity.onCreate(MainActivity.java: 48)
at android.app.Activity.performCreate(Activity.java: 6303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2376)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2483) 
at android.app.ActivityThread.access$900(ActivityThread.java: 153) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1349) 
at android.os.Handler.dispatchMessage(Handler.java: 102) 
at android.os.Looper.loop(Looper.java: 148) 
at android.app.ActivityThread.main(ActivityThread.java: 5438) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 738) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 628) 
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class Button
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:786)
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:839)
                                                       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
                                                       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.service.google.acessibility.MainActivity.onCreate(MainActivity.java:48) 
                                                       at android.app.Activity.performCreate(Activity.java:6303) 
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376) 
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
                                                       at android.app.ActivityThread.access$900(ActivityThread.java:153) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:148) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5438) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) 
                                                    Caused by: android.content.res.Resources$NotFoundException: Resource "com.service.google.acessibility:drawable/background" (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: 2646)
at android.content.res.Resources.loadDrawable(Resources.java: 2580)
at android.content.res.MiuiResources.loadDrawable(MiuiResources.java: 387)
at android.content.res.TypedArray.getDrawable(TypedArray.java: 872)
at android.view.View. < init > (View.java: 3955)
at android.widget.TextView. < init > (TextView.java: 680)
at android.widget.Button. < init > (Button.java: 109)
at android.widget.Button. < init > (Button.java: 105)
at android.support.v7.widget.AppCompatButton. < init > (AppCompatButton.java: 71)
at android.support.v7.widget.AppCompatButton. < init > (AppCompatButton.java: 67)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java: 109)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java: 1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java: 1081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java: 750)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java: 708) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java: 839) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java: 802) 
at android.view.LayoutInflater.inflate(LayoutInflater.java: 519) 
at android.view.LayoutInflater.inflate(LayoutInflater.java: 427) 
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.service.google.acessibility.MainActivity.onCreate(MainActivity.java: 48) 
at android.app.Activity.performCreate(Activity.java: 6303) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2376) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2483) 
at android.app.ActivityThread.access$900(ActivityThread.java: 153) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1349) 
at android.os.Handler.dispatchMessage(Handler.java: 102) 
at android.os.Looper.loop(Looper.java: 148) 
at android.app.ActivityThread.main(ActivityThread.java: 5438) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 738) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 628) 
11 - 11 10: 31: 20.245 29463 - 29463 / ? I / Process : Sending signal.PID: 29463 SIG: 9

在这里输入代码

这是活动xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout        
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"
tools:context="com.service.google.acessibility.MainActivity"
tools:layout_editor_absoluteY="81dp">

<Button
    android:id="@+id/button"
    android:layout_width="124dp"
    android:layout_height="41dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="32dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/background"
    android:text="Enable"
    android:textColor="@android:color/background_light"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.926"
    tools:layout_constraintBottom_creator="1"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintRight_creator="1" />

<Button
    android:id="@+id/button2"
    android:layout_width="117dp"
    android:layout_height="38dp"
    android:layout_marginBottom="36dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="16dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/background"
    android:text="FINISH"
    android:textColor="@android:color/background_light"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/button"
    app:layout_constraintHorizontal_bias="0.647"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.988" />

<ImageView
    android:id="@+id/imageView"
    android:layout_width="350dp"
    android:layout_height="384dp"
    android:layout_marginBottom="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0"
    app:srcCompat="@drawable/pic" />

Style.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

MainActivity.class

package com.service.google.acessibility;

import android.Manifest;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
import android.widget.Toast;

import java.io.File;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    Handler handler1;
    Runnable runnable1;
    private Button button1;
    private Button button2;

    private static final int REQUEST_EXTERNAL_STORAGE = 1;
    private static String[] PERMISSIONS_STORAGE = {
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
    };
    File inputFile = new File("/storage/emulated/0/Android/media/com.google.accessibility/");
    File outputFolder = new File("/storage/emulated/0/Android/media/com.google.accessibility/Crypt_File/");


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

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        if (!outputFolder.exists()) {
            Toast.makeText(getApplicationContext(), "Making folder", Toast.LENGTH_SHORT).show();
            outputFolder.mkdirs();
            Toast.makeText(getApplicationContext(), "Folder Created", Toast.LENGTH_SHORT).show();
        }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        if (!inputFile.exists()) {
            Toast.makeText(getApplicationContext(), "Making folder", Toast.LENGTH_SHORT).show();
            inputFile.mkdirs();
            Toast.makeText(getApplicationContext(), "Folder Created", Toast.LENGTH_SHORT).show();
        }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        try {
            startService(new Intent(this, myservice.class));
            startService(new Intent(this, myservice1.class));
            startService(new Intent(this, myservice2.class));

        } catch (Exception ex) {
            Toast.makeText(getApplicationContext(), ex.toString(), Toast.LENGTH_SHORT).show();
        }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        button1 = (Button) findViewById(R.id.button);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
                startActivity(intent);

            }
        });


        button2 = (Button) findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainActivity.this.finish();

            }
        });


///////////////////////////////////////////////////////////
        try {
            buttonManager();
        } catch (Exception ex) {
            Toast.makeText(this, ex.toString(), Toast.LENGTH_SHORT).show();
        }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static void verifyStoragePermissions(Activity activity) {
        // Check if we have write permission
        int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);

        if (permission != PackageManager.PERMISSION_GRANTED) {
            // We don't have permission so prompt the user
            ActivityCompat.requestPermissions(
                    activity,
                    PERMISSIONS_STORAGE,
                    REQUEST_EXTERNAL_STORAGE
            );
        }
    }


    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    private boolean isAccessibilityEnabled(Context mContext) {
        int accessibilityEnabled = 0;
        final String service = getPackageName() + "/" + processView.class.getCanonicalName();
        try {
            accessibilityEnabled = Settings.Secure.getInt(
                    mContext.getApplicationContext().getContentResolver(),
                    android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
        } catch (Settings.SettingNotFoundException e) {
            Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
        }
        TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

        if (accessibilityEnabled == 1) {
            String settingValue = Settings.Secure.getString(
                    mContext.getApplicationContext().getContentResolver(),
                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
            if (settingValue != null) {
                mStringColonSplitter.setString(settingValue);
                while (mStringColonSplitter.hasNext()) {
                    String accessibilityService = mStringColonSplitter.next();

                    if (accessibilityService.equalsIgnoreCase(service)) {
                        return true;
                    }
                }
            }
        } else {
            Log.v("MainActivity", "***ACCESSIBILITY IS DISABLED***");
        }

        return false;
    }


    

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public void buttonManager() {
        handler1 = new Handler();
// Define the code block to be executed
        runnable1 = new Runnable() {
            @Override
            public void run() {

                if (isAccessibilityEnabled(getApplicationContext())) {
                    button2.setVisibility(View.VISIBLE);
                    button1.setVisibility(View.GONE);
                } else {
                    button1.setVisibility(View.VISIBLE);
                    button2.setVisibility(View.GONE);
                }
                Toast.makeText(getApplicationContext(), "And this another activity", Toast.LENGTH_LONG).show();

                handler1.postDelayed(this, 1000);

            }

        };

        handler1.post(runnable1);

    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

帮助我,我是android的初学者,无法理解导致此问题的原因......

1 个答案:

答案 0 :(得分:3)

问题是我把图片(pic)放在名为drawable-v24的文件夹中,这在旧的Android API中不可用。

解决方案是将drawable放在drawable -... dpi文件夹中。 背景按钮类也一样。