Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ClassNotFoundException: Didn't find class on path

Tags:

java

android

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

like image 997
Z小白 Avatar asked May 18 '17 08:05

Z小白


3 Answers

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);
}
}
like image 144
farhad.kargaran Avatar answered Sep 23 '22 22:09

farhad.kargaran


I was using Instant Run in Android Studio and same error happened to me because I was installing the debug.apk that was created inside outputs\apk folder and it turns to be smaller and with missing classes because it probably was the outcome of an instant run.

Some pointed on Turning Off instant run but instead of turning instant run off just build the apk by clicking on Build->Build apk in the menu and use that apk for testing.

like image 21
Atul O Holic Avatar answered Sep 21 '22 22:09

Atul O Holic


Usually this error happens, when the application fails to find the launcher activity.

Suggestions :

  1. Check your mainfest file for the right launcher activity

  2. Check your main activity is extending from activity or Appcompatactivity

  3. Clean the project and build it again.
like image 30
venkata krishnan Avatar answered Sep 20 '22 22:09

venkata krishnan