Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app ClassNotFoundException for main activity

Tags:

Most of the devices can run my app but I got this error report :

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.company.app/com.company.app.MainActivity}: java.lang.ClassNotFoundException: com.company.app.MainActivity in loader dalvik.system.PathClassLoader[/mnt/asec/com.company.app-1/pkg.apk] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2755) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2854) at android.app.ActivityThread.access$2300(ActivityThread.java:136) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:143) at android.app.ActivityThread.main(ActivityThread.java:5068) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: com.company.app.MainActivity in loader dalvik.system.PathClassLoader[/mnt/asec/com.company.app-1/pkg.apk] at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) at java.lang.ClassLoader.loadClass(ClassLoader.java:573) at java.lang.ClassLoader.loadClass(ClassLoader.java:532) at android.app.Instrumentation.newActivity(Instrumentation.java:1034) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2747) ... 11 more 

I found there is a related answer: ClassNotFoundException Android

but the question is, my exception occurs before any line of code i write, so how can I ensure the class loader is loaded?

like image 231
Kay Chan Avatar asked May 27 '11 02:05

Kay Chan


1 Answers

I had exactly the same problem. Suddenly my app stopped working. I didint make any change to manifest, but with some accident there was missing first row:

<?xml version="1.0" encoding="utf-8"?>

This caused ClassNotFoundException for launcher activity. I was struggling with that for few hours and I overlooked this every time I was checking manifest for possible mistake.

Strange thing happened after I have deleted this row again. Suprise, suprise app was still working. (and I didnt forget to rebuild app)

Hope this help someone to save few hours.

like image 155
Koso Avatar answered Oct 16 '22 18:10

Koso