Skip to content Skip to sidebar Skip to footer

"Unable To Instantiate Activity" Error

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:

Solution 1:

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.


Solution 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.


Solution 3:

Well there are couple of suggestions that might help you debug your application. Hope they solve your issue. Also post your Android Manifest XML file and your MainActivity's onCreate Method snippet so that we could also help you debug it too and narrow down the possibilities ...

Suggestions:

1) In your Android XML , check if your minimum Sdk version (android:minSdkVersion="3") is 3 ? If it is change it to 7+ . I have found this trick helpful sometimes while coping up with rare issues.

2) In your Android XML, check your that you have registered your Activity there. If not please register it, each new activity has to be registered before using it. If your activity is registered, recheck the path that you are supplying to it is also correct.

3) Clean the project and build it again , so that the R.java is updated and doesn't uses any cached files.

4) Migrate your project , make one new project and copy all your files there. It also solves rare issues.

5) According to one user :

I just got the same error (Unable to instantiate activity...) with Opera Mini. Opera Mini was on SD card (moved to SD card in the app setting). The error seems to be related to the fact that I swapped the SD card yesterday. The device was shutdown, I copied all data from the old card over to the new card (with cp -a) and then inserted the new card and started the device again. Everything seems to work as expected, but I see now that all apps on the SD card crashes with the same error.

Device: HTC Desire HD (Android 2.2)
Old SDHC card: SanDisk 8GB class 4
New SDHC card: Kingston 16GB class 4

So I would say that this is a an Android bug and not something that can be fixed by app developers.

Also see: http://android-developers.blogspot.com/2010/07/apps-on-sd-card-details.html

It has always been the case that when you swap SD cards on an Android device, if you physically copy the contents of the old card to the new one, the system will use the data on the new card as if nothing had changed. This is also true of apps which have been installed on the SD card."

This seems to be incorrect.

Hope one of these solve your problem.


Solution 4:

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

ClassLoader myClassLoader = TroubleClass.class.getClassLoader();
Thread.currentThread().setContextClassLoader(myClassLoader);

Solution 5:


Post a Comment for ""Unable To Instantiate Activity" Error"