dalvik.system.BaseDexClassLoader.findClass 中的 java.lang.ClassNotFoundException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41426853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 05:52:00  来源:igfitidea点击:

java.lang.ClassNotFoundException in dalvik.system.BaseDexClassLoader.findClass

javaandroid

提问by Joel

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.me.hexavoidaa/com.me.hexavoidaa.PTPlayer}: java.lang.ClassNotFoundException: Didn't find class "com.me.hexavoidaa.PTPlayer" on path: DexPathList[[zip file "/data/app/com.me.hexavoidaa-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.me.hexavoidaa-1, /vendor/lib, /system/lib]]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2208)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
    at android.app.ActivityThread.access0(ActivityThread.java:157)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5293)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.me.hexavoidaa.PTPlayer" on path: DexPathList[[zip file "/data/app/com.me.hexavoidaa-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.me.hexavoidaa-1, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
    ... 11 more

回答by Ranjith KP

add this to gradle.build:

将此添加到 gradle.build:

defaultConfig {
...
minSdkVersion 14
targetSdkVersion // your version 
...

// Enabling multidex support.
multiDexEnabled true
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

回答by AlexS

In Android 9 likely to help adding to manifest into "application" tag:

在 Android 9 中可能有助于将清单添加到“应用程序”标签中:

<uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

回答by kc ochibili

In some cases, this could be a MultiDex issue. Try this in your application class. That is in App.javawhich extends Application:

在某些情况下,这可能是 MultiDex 问题。在您的应用程序类中试试这个。那就是App.java其中扩展Application

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this); // this is the key code
}

source: https://github.com/opendatakit/collect/issues/387

来源:https: //github.com/opendatakit/collect/issues/387

回答by Muhammad Natiq

if you already added multidex in both gradle and manifest then try to disable instant run and then create apk to test, i was facing same issue and searched a lot and tried every solution but at last this solved my problem

如果您已经在 gradle 和 manifest 中添加了 multidex 然后尝试禁用即时运行然后创建 apk 进行测试,我遇到了同样的问题并进行了大量搜索并尝试了所有解决方案,但最后这解决了我的问题