Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

java - Android ClassNotFoundException: Didn't find class on path

Here's the exception message that I get when I launch the app.

FATAL EXCEPTION: main Process: net.johnhany.opencv3jniPID: 10721 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.johnhany.opencv3jni/net.johnhany.opencv3jni.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "net.johnhany.opencv3jni.MainActivity" on path: DexPathList[[zip file "/data/app/net.johnhany.opencv3jni-1/base.apk"],nativeLibraryDirectories=[/data/app/net.johnhany.opencv3jni-1lib/arm, /vendor/lib, /system/lib]] at android.app.ActivityThread.performLaunchActivityActivityThread.java:2322) at android.app.ActivityThread.handleLaunchActivityActivityThread.java:2474) at android.app.ActivityThread.ess$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessageActivityThread.java:1359) at android.os.Handler.sage(Handler.java:102) at android.os.Looper.loopLooper.java:155) at android.app.ActivityThread.mainActivityThread.java:5696) at java.lang.reflect.Method.invokeNative Method) at java.lang.reflect.Method.invokeMethod.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.runZygoteInit.java:1028) at com.android.internal.os.Init.main(ZygoteInit.java:823) Caused by: java.lang.ClassNotFoundException: Didn't find class "net.johnhany.opencv3jni.MainActivity" on path: DexPathList[[zip file "/data/app/net.johnhany.opencv3jni-1/base.apk"],nativeLibraryDirectories=[/data/app/net.johnhany.opencv3jni-1/lib/arm/vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClassBaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClassClassLoader.java:511) at java.lang.ClassLoader.loadClassClassLoader.java:469) at android.app.Instrumentation.newActivityInstrumentation.java:1083) at android.app.ActivityThread.performLaunchActivityActivityThread.java:2312) at android.app.ActivityThread.handleLaunchActivityActivityThread.java:2474)? at android.app.ActivityThread.ess$800(ActivityThread.java:144)? at android.app.ActivityThread$H.handleMessageActivityThread.java:1359)? at android.os.Handler.sage(Handler.java:102)? at android.os.Looper.loopLooper.java:155)? at android.app.ActivityThread.mainActivityThread.java:5696)? at java.lang.reflect.Method.invokeNative Method)? at java.lang.reflect.Method.invokeMethod.java:372)? at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.runZygoteInit.java:1028)? at com.android.internal.os.Init.main(ZygoteInit.java:823)? Suppressed: java.lang.ClassNotFoundException: net.johnhany.opencv3jni.ty at java.lang.Class.classForNameNative Method) at java.lang.BootClassLoader.Class(ClassLoader.java:781) at java.lang.BootClassLoader.Class(ClassLoader.java:841) at java.lang.ClassLoader.loadClassClassLoader.java:504) ... 13 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 05-18 16:01:27.927 645-1928/? E/ActivityManager: App crashedProcess: net.johnhany.opencv3jni

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

My problem solved using use multi dex:

android {
defaultConfig {

    // Enabling multidex support.
    multiDexEnabled true
}
...
}
dependencies 
{
compile 'com.android.support:multidex:1.0.0'
}

If you do not override the Application class, edit your manifest file to set android:name in the tag as follows:

<application
        android:name="android.support.multidex.MultiDexApplication" >
    ...
</application>

If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:

public class MyApplication extends MultiDexApplication

Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:

public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
 super.attachBaseContext(base);
 MultiDex.install(this);
}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...