我找到了几篇关于MainActivity的classNotFound的帖子,但似乎都与主应用程序和支持库之间的库差异有关,就像那样。我有一种情况,我只是在Android Studio中创建一个新的应用程序,并且没有修改,运行helo world默认应用程序,失败并出现此错误。
07-20 23:25:46.012 7152-7152/com.rythmair.lvlvalidation D/AndroidRuntime: Shutting down VM
07-20 23:25:46.012 7152-7152/com.rythmair.lvlvalidation E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rythmair.lvlvalidation, PID: 7152
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.rythmair.lvlvalidation/com.rythmair.lvlvalidation.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.rythmair.lvlvalidation.MainActivity" on path: DexPathList[[zip file "/data/app/com.rythmair.lvlvalidation-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2968)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3233)
at android.app.ActivityThread.access$1000(ActivityThread.java:197)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6873)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.rythmair.lvlvalidation.MainActivity" on path: DexPathList[[zip file "/data/app/com.rythmair.lvlvalidation-1/base.apk"],nativeLibraryDirectories=[/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 android.app.Instrumentation.newActivity(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2958)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3233)
at android.app.ActivityThread.access$1000(ActivityThread.java:197)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6873)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Suppressed: java.lang.ClassNotFoundException: com.rythmair.lvlvalidation.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 not found using the boot class loader; no stack available
07-20 23:26:13.377 7152-7152/com.rythmair.lvlvalidation I/Process: Sending signal. PID: 7152 SIG: 9
不确定我在这里缺少什么。
答案 0 :(得分:0)
如果不存在
,请尝试将其放入清单中<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
答案 1 :(得分:0)
鉴于错误,这是一个奇怪的。问题原来是我正在测试的设备上的访问权限(我认为)。我陷入了堆栈的一部分,它无法将代码写入数据/数据/ ...在进一步挖掘后,我发现我作为测试用户登录了我的平板电脑,用于验证许可功能。以这个用户身份登录时,只要我尝试使用上面显示的错误构建应用程序,它就会失败。一旦我以自己的身份重新登录平板电脑,此问题就不再发生了。