我有一个项目正在进行中,一切都是正确的,因为我在android studio中使用一个Activity(登录活动)创建项目 后来因为我想在项目上实现MVC,我在原始包com.otemainc.smartmenu中创建了另外三个包(app,activity和helper)然后我将LoginActivity.java文件移动到了活动包。 然后将R类导入其中,将打包的声明行更改为正确的,但当我在手机上运行时,它会给我以下错误
12-16 13:07:27.352 4608-4608/com.otemainc.smartmenu E/AndroidRuntime: FATAL EXCEPTION: main Process: com.otemainc.smartmenu, PID: 4608
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.otemainc.smartmenu/com.otemainc.smartmenu.LoginActivity}: java.lang.ClassNotFoundException: Didn't find class "com.otemainc.smartmenu.LoginActivity" on path: DexPathList[[zip file "/data/app/com.otemainc.smartmenu-1/base.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
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:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.otemainc.smartmenu.LoginActivity" on path: DexPathList[[zip file "/data/app/com.otemainc.smartmenu-1/base.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.otemainc.smartmenu-1/split_lib_slice_9_apk.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:1071)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
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:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Suppressed: java.lang.ClassNotFoundException: com.otemainc.smartmenu.LoginActivity
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
答案 0 :(得分:1)
此错误是因为未找到您的活动类,因为您将其移动到另一个文件夹,您需要更改清单文件中的活动名称。你会看起来像这样
<activity
android:name=".LoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这意味着正在原始根包中查找活动文件。您需要将名称变为activity.LoginActivity。 代码看起来像这样
<activity
android:name=".activity.LoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>