27

One of my Android apps has about 100,000 users and, about 10 times a week, I get the following exception being reported to me via Google's market tool:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.rebm.asp/org.rebm.asp.MainActivity}:
  java.lang.ClassNotFoundException: org.rebm.asp.MainActivity in loader dalvik.system.PathClassLoader[/mnt/asec/org.rebm.asp-1/pkg.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
at android.app.ActivityThread.access$2500(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
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:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: org.rebm.asp.MainActivity in loader dalvik.system.PathClassLoader[/mnt/asec/org.rebm.asp-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:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2651)
... 11 more

From searching online, this error usually indicates something is wrong with the manifest file and the package names being used. However, I can't reproduce this error on my own devices or on the emulator. I only know of this error through the market tool. All I can conclude is that it's a rare error because I know lots of people are using the app and none of the reviews indicate it crashes.

Does anyone know what the issue might be or how I can diagnose it?

rbcc
  • 2,452
  • 3
  • 26
  • 28
  • I just noticed the first occurrence of the same error on one of my apps. Would love to know what could cause this. I'm starting a bounty.. – Kon Mar 25 '11 at 13:47
  • Wow, thanks Kon. Bounties really seem to motivate people to answer a question that has had no replies for over a month! I'm still consistently getting this error message in my market console unfortunately and I'm not closer to working out what's wrong or how to fix it. – rbcc Mar 29 '11 at 14:05
  • I haven't seen a reoccurrence - just had it happen once, but it's still bugging me. – Kon Mar 29 '11 at 15:47
  • Many discussions here http://stackoverflow.com/questions/4820554/android-unable-to-instantiate-activity-classnotfoundexception – Jett Hsieh Mar 31 '11 at 17:21
  • I have this too since I have set in the AndroidManifest android:installLocation=prefersExternal – Arnaud May 08 '11 at 07:26
  • @FelipeCaldas, if you use library project, check out [this answer](http://stackoverflow.com/questions/10866431/android-activity-classnotfoundexception-tried-everything/10965393#10965393), the question has exactly the same stack trace, following instructions in that answer and see if you can reproduce it. – yorkw Apr 14 '13 at 23:17
  • I also have this problem in my app (over 200,000 users), and it also appears to be SD card related. Using installLocation="auto" in manifest basically doesn't work. Aside from this error, sometimes my app icon mysteriously disappears from users home screens because of SD card issues. SD card install is broken in Android, but only effects a small percentage of users, so it hasn't been fixed yet. – Fraggle Oct 06 '13 at 15:00

5 Answers5

15

The stack trace that you give in the question contains the proof that the problem is due to moving the app to the SD card:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.rebm.asp/org.rebm.asp.MainActivity}: java.lang.ClassNotFoundException: org.rebm.asp.MainActivity in loader dalvik.system.PathClassLoader[/mnt/asec/org.rebm.asp-1/pkg.apk]

As you can see, the path to your application is contains /mnt/asec which is the Android secure application mount point.

In order to verify if this problem happens due to Apps2SD, you should check to see if all the stack traces you have include the /mnt/asec directory in the path to your application. If they are all so, you can be sure that it is an Apps2SD error.

As others have said, these kinds of problems sometime arise due to the SD card not being available when the application is being loaded or from a corrupt asec partition on the SD card.

Does your app, in any way, register itself to launch at boot or is it some sort of a widget that the system would try to load even when the SD card has not been mounted yet? If so, maybe you should turn off the option of moving the app to the SD card.

paracycle
  • 7,665
  • 1
  • 30
  • 34
  • 2
    I can confirm all my stack traces (about 50 of them) contain the /mnt/asec line. It's a game, so it doesn't need any special treatment on booting. – rbcc Apr 01 '11 at 13:24
  • 1
    Interesting answer. The problem it's there is no response from google for this issue... – ol_v_er Aug 24 '12 at 10:04
2

Having the same "rare" issue on all published games.

Might be an issue with installs to SD card, or moving app to the SD card, then removing the SD card.

Other guess is that the app gets downloaded or installed multiple times somehow.

I haven't been able to reproduce this so not able to nail it down either.

  • I can confirm that the app in my question has move to SD enabled and set to perform the move by default. – rbcc Mar 29 '11 at 07:48
1

I had this issue but not with activity. Fixed with a workaround:

ClassLoader myClassLoader = TroubleClass.class.getClassLoader();
Thread.currentThread().setContextClassLoader(myClassLoader);
Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
  • 1
    Could you explain what this does and why you think it would work? – rbcc Mar 29 '11 at 14:03
  • I'm not a real expert in the problem, but it seems that dalvik due to some bug doesn't have necessary classloaders for some classes. I don't know why this bug arrises, but if you explicitly tell him to use classloader of needed class, the issue goes away. – Vladimir Ivanov Mar 29 '11 at 14:05
  • Where would this code be placed though? The error seems to indicate that the activity itself can't be started so the there is nowhere I could see to place the code. – rbcc Mar 29 '11 at 21:18
  • As all activities are launched in ui thread, you can try to add this code before you send an intent. – Vladimir Ivanov Mar 30 '11 at 03:51
  • My app is a game with a single activity that is launched on startup. I don't see where I could add this code if the activity itself is presumably not starting. – rbcc Mar 31 '11 at 18:15
  • 1
    Try to add it in the static block of your class. Though if it not found, it can't be loaded. – Vladimir Ivanov Mar 31 '11 at 18:24
0

It may happen that the app works fine on your eclipse and mobile, when you install it from eclipse but may crash when in the market (Happened to me), if the same happens to you, there are 2 things you need to do and you will get out of this situation.

  1. Clean the project and rebuild. (Using Project-Clean)
  2. Delete and re-include the libraries, if any.
divyenduz
  • 2,037
  • 19
  • 38