我在app.gradle中添加了android.annotation。 “
当我用 Intent next = new Intent(MainMenu.this,MainActivity.class); 我收到运行时错误。错误消息是
"03-05 09:52:19.210 1339-1339/com.example.tesingphootc55 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tesingphootc55, PID: 1339
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/tesingphootc55/MainActivity;
at com.example.tesingphootc55.MainMenu$CheckSequentialClosing.onPostExecute(MainMenu.java:2125)
at com.example.tesingphootc55.MainMenu$CheckSequentialClosing.onPostExecute(MainMenu.java:2092)
at android.os.AsyncTask.finish(AsyncTask.java:636)
at android.os.AsyncTask.access$500(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5276)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.tesingphootc55.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.tesingphootc55-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.tesingphootc55-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.example.tesingphootc55.MainMenu$CheckSequentialClosing.onPostExecute(MainMenu.java:2125)
at com.example.tesingphootc55.MainMenu$CheckSequentialClosing.onPostExecute(MainMenu.java:2092)
at android.os.AsyncTask.finish(AsyncTask.java:636)
at android.os.AsyncTask.access$500(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5276)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)
Suppressed: java.lang.NoClassDefFoundError: com.example.tesingphootc55.MainActivity
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:321)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 14 more
Suppressed: java.lang.ClassNotFoundException: com.example.tesingphootc55.MainActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class is not found using the boot class loader; no stack available
"
答案 0 :(得分:0)
我也尝试过的一种可能的解决方案是禁用即时运行goto 文件->设置->构建,执行,部署->即时运行->取消选中即时运行复选框。 >
在设备上运行项目之前,请先对其进行清洁。
修改
如果您的应用程序及其引用的库超过65k方法限制,请确保启用 multidex选项。为了在gradle build中支持multidex,请添加依赖项
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
然后在defaultConfig中添加multiDexEnabled
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
有关multidex的更多信息,请访问android developer link
答案 1 :(得分:0)