![](/img/trans.png)
[英]java.lang.RuntimeException: Unable to instantiate application com.todos.MyApplication: java.lang.ClassNotFoundException
[英]java.lang.RuntimeException: Unable to instantiate application com.projec.App: java.lang.ClassNotFoundException
为什么会出现这样的错误,即使该错误以前从未出现过并且我创建的应用程序只是一个用于尝试recyclerviewpool
的应用程序。 这是一个 logcat 错误:
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]]
我试图从其他论坛找到解决方案,并将其添加到文件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.
如何处理 java.lang.ClassNotFoundException
验证请求的 class 的名称是否正确,并且您的类路径中是否存在适当的.jar 文件。 如果没有,您必须将其显式添加到应用程序的类路径中。
如果指定的.jar 文件存在于您的类路径中,那么您的应用程序的类路径将被覆盖,您必须找到应用程序使用的确切类路径。
如果异常是由第三方 class 引起的,则必须识别引发异常的 class,然后在类路径中添加 missing.jar 文件。
我有同样的问题。
通过从AndroidManifest.xml
中删除它来解决它
<application
android:name="com.project.gemastik.tugas.App" <- Remove this entire line
或者,使用相对路径并尝试将其重命名为:
<application
android:name=".App"
在那之前,我厌倦了使缓存失效、Project Clean、删除build
、 .gradle
和.idea
文件夹,将所有内容升级到最新版本。 没有别的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.