简体   繁体   中英

java.lang.RuntimeException: Unable to instantiate application com.projec.App: java.lang.ClassNotFoundException

why an error like this appears, even though the error has never appeared before and app I created is just an app for trying recyclerviewpool . this is a logcat error:

java.lang.RuntimeException: Unable to instantiate application com.project.gemastik.tugas.App: java.lang.ClassNotFoundException: Didn't find class "com.project.gemastik.tugas.App" on path: DexPathList[[zip file "/data/app/com.project.gemastik.tugas-uVGTf_nK3aGr3gdwLH3zAA==/base.apk"],nativeLibraryDirectories=[/data/app/com.project.gemastik.tugas-uVGTf_nK3aGr3gdwLH3zAA==/lib/arm, /system/lib, /vendor/lib]]
    at android.app.LoadedApk.makeApplication(LoadedApk.java:1003)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5819)
    at android.app.ActivityThread.-wrap1(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1708)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:6662)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.project.gemastik.tugas.App" on path: DexPathList[[zip file "/data/app/com.project.gemastik.tugas-uVGTf_nK3aGr3gdwLH3zAA==/base.apk"],nativeLibraryDirectories=[/data/app/com.project.gemastik.tugas-uVGTf_nK3aGr3gdwLH3zAA==/lib/arm, /system/lib, /vendor/lib]]

I've tried to find solutions from other forums, and I've added this in file build.gradle (module: app)

 android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "com.project.gemastik.tugas"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        preDexLibraries false
    }
}
...

As the name suggests classNotFoundException in Java is a subclass of java.lang.Exception and comes when Java Virtual Machine tries to load a particular class and doesn't find the requested class in the classpath.

How to deal with the java.lang.ClassNotFoundException

Verify that the name of the requested class is correct and that the appropriate.jar file exists in your classpath. If not, you must explicitly add it to your application's classpath.

In case the specified.jar file exists in your classpath then, your application's classpath is getting overridden and you must find the exact classpath used by your application.

In case the exception is caused by a third party class, you must identify the class that throws the exception and then, add the missing.jar files in your classpath.

I had the same problem.

Got it resolved by removing this from AndroidManifest.xml

<application
    
      android:name="com.project.gemastik.tugas.App" <- Remove this entire line

Alternatively, use relative paths and try to rename it to:

<application
    
      android:name=".App"

Before that I tired invalidating caches, Project Clean, delete build , .gradle and .idea folders, upgraded everything to the latest versions. Nothing else worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM