java.lang.ClassNotFoundException 从 APK 安装应用时

java.lang.ClassNotFoundException when install app from APK

我在下面描述的错误发生在:

在以下情况下不会发生错误:

    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{my.package/my.package.MainActivity}:

java.lang.ClassNotFoundException: my.package.MainActivity

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1998)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2099)
at android.app.ActivityThread.access0(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4929)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: my.package.MainActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1056)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1989)
... 11 more

我一如既往地导出 APk,来自 "Use the Export Wizard to export and sign an APK"

知道吗,因为它来自 APK 而不是直接来自 eclipse?

以上错误是我造成的。但用户的反映有些不同:

用户 1:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{my.package/my.package.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "my.package.MainActivity" on path: DexPathList[dexElements=[zip file "/data/app/my.package-1.apk"],nativeLibraryDirectories=[/data/app-lib/my.package-1, /vendor/lib, /system/lib]]

用户 2:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{my.package/my.package.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "my.package.MainActivity" on path: DexPathList[[zip file "/data/app/my.package-1.apk"],nativeLibraryDirectories=[/data/app-lib/my.package-1, /vendor/lib, /system/lib]]

清单:

<?xml version="1.0" encoding="utf-8"?> <manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package"
android:versionCode="12"
android:versionName="2.3" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/motion"
    android:label="@string/app_name"
    android:largeHeap="true" 
    android:theme="@style/Theme.AppCompat.Light"  >


    <activity
        android:name="my.package.MainActivity"
        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 android:name="my.package.AlarmsListActivity" 
               android:theme="@style/dialogTheme"/>
     <activity android:name="my.package.ImagenesActivity"/>         
     <activity android:name="my.package.EndActivity" />  


</application>

</manifest>

我在 MainActivity 中使用了以下库

这是你的错误:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{my.package/my.package.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "my.package.MainActivity" on path: DexPathList[dexElements=[zip file "/data/app/my.package-1.apk"],nativeLibraryDirectories=[/data/app-lib/my.package-1, /vendor/lib, /system/lib]]

解法:

您已将库项目添加为对项目的引用,也可能是您在 libs 文件夹中为 ChartViewsupport-v7 添加了 jar 文件,并且还作为 Add External Jars。因此,您必须在 order and export menu.

中启用 android-support-v7.jar 文件和 chartview jar 文件的复选框

它的路径是,

Project - Right Click - Properties - Java Build Path - Order and Export Menu.

最后您需要清理并运行您的项目。