无法启动活动二进制XML文件错误膨胀类,在Dex路径列表中找不到类 - Android

时间:2015-10-28 12:49:33

标签: android exception sdk android-custom-view layout-inflater

我一直在使用一个正常工作的customViewClass,直到我从 19 升级我的compileSdkVersiontargetSdkVersion 22 。 它仍适用于compileSdkVersion 19

在堆栈跟踪中,您还可能会看到它也会抛出ClassNotFoundException,因为它不存在DexPathList

这是我的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "uk.org.example.hfi"
        minSdkVersion 16
        targetSdkVersion 22
        multiDexEnabled true
    }
    dexOptions {
        jumboMode = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile project(':dragSortListview')
    compile 'com.github.bumptech.glide:glide:3.5.2'
    compile 'com.android.support:support-v4:22.1.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile files('libs/android-query-full.0.26.7.jar')
    compile files('libs/aws-android-sdk-2.1.5-cognito.jar')
    compile files('libs/aws-android-sdk-2.1.5-core.jar')
    compile files('libs/aws-android-sdk-2.1.5-s3.jar')
    compile files('libs/isoviewer-2.0-RC-22.jar')
    compile files('libs/javacpp.jar')
    compile files('libs/javacv.jar')
    compile files('libs/libGoogleAnalyticsServices.jar')
}

这是我的自定义ViewClass

package uk.org.example.hfi.CustomClasses;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

public class RatioImageView extends ImageView {

    public RatioImageView(Context context) {
        super(context);
    }

    public RatioImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RatioImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int h = MeasureSpec.getSize(heightMeasureSpec);
            int w = h*3/4;
            setMeasuredDimension(w, h);
    }
}

这就是我使用它的方式

<uk.org.example.hfi.CustomClasses.RatioImageView
                    android:id="@+id/iv_ProfileImage"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:src="@drawable/profile_pic"
                    android:scaleType="centerInside"/>

这里是完整的Stack Trace:Dex也会抛出class not found异常

.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime: FATAL EXCEPTION: main
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime: Process: uk.org.humanfocus.hfi, PID: 10025
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.org.humanfocus.hfi/uk.org.humanfocus.hfi.Home.MainActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class uk.org.humanfocus.hfi.CustomClasses.RatioImageView
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2436)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.access$900(ActivityThread.java:170)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:146)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5635)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:  Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class uk.org.humanfocus.hfi.CustomClasses.RatioImageView
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:352)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.Activity.setContentView(Activity.java:2057)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at uk.org.humanfocus.hfi.Home.MainActivity.onCreate(MainActivity.java:259)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5580)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.access$900(ActivityThread.java:170) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:146) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5635) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:  Caused by: java.lang.ClassNotFoundException: Didn't find class "uk.org.humanfocus.hfi.CustomClasses.RatioImageView" on path: DexPathList[[zip file "/data/app/uk.org.humanfocus.hfi-1.apk"],nativeLibraryDirectories=[/data/app-lib/uk.org.humanfocus.hfi-1, /vendor/lib, /system/lib]]
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.createView(LayoutInflater.java:565)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:352) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.Activity.setContentView(Activity.java:2057) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at uk.org.humanfocus.hfi.Home.MainActivity.onCreate(MainActivity.java:259) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5580) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.access$900(ActivityThread.java:170) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:146) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5635) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
10-28 17:28:50.545 10025-10025/uk.org.humanfocus.hfi E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 

请不要将其标记为重复,因为我已经尝试了所有其他答案而且没有其他人为我工作过!

1 个答案:

答案 0 :(得分:1)

由于您将compileSdkVersion和targetSdkVersion从19升级到22,因此您的buildToolsVersion应相应升级,例如:

compileSdkVersion 22
buildToolsVersion "22.0.0"

如果你有buildToolsVersion&gt; = 22,请将buildToolsVersion更改为它,否则你应该使用sdkmanager下载它。