This question already has an answer here:
The error I describe below, occurs when:
- Install the app on a device directly from the APK.
- Download the app by Play Store
The error don´t occurs when:
- Install apk through Eclipse pressing the 'run' button
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.access$600(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
To export the APk I do as always, from "Use the Export Wizard to export and sign an APK"
Any idea because it occurs from the APK but not directly from eclipse?
The above error is generated by me. But reports of users are somewhat different:
User1:
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]]
User2:
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]]
Manifest:
<?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>
I use the following libraries in MainActivity

This is your error:
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]]
Solution:
You have added library project as a reference to your project and also may be you have added jar files for ChartView
and support-v7
in your libs
folder and also as a Add External Jars
. So you have to enable both checkboxes for android-support-v7.jar
file and for chartview jar
file in order and export menu
.
The path for it is,
Project - Right Click - Properties - Java Build Path - Order and Export Menu.
Finally you need to clean and run your project.
来源:https://stackoverflow.com/questions/27739834/java-lang-classnotfoundexception-when-install-app-from-apk