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?
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.
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 had this issue but not with activity. Fixed with a workaround:
ClassLoader myClassLoader = TroubleClass.class.getClassLoader();
Thread.currentThread().setContextClassLoader(myClassLoader);
Try the following links:
“Unable to instantiate activity 1”
“Unable to instantiate activity 2”
Force close after adding resources and textview
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.
- Clean the project and rebuild. (Using Project-Clean)
- Delete and re-include the libraries, if any.
精彩评论