3 June 2013

How to solve error, radomly seen on developer console in google play "java.lang.RuntimeException: Unable to instantiate activity ComponentInfo {...} ?

INFO: If you are user of my apps and your are redirect here look on bottom of the post.

STORY:

You look in developer console and you see crash report:
java.lang.ClassNotFoundException 
in dalvik.system.PathClassLoader.findClass

and message which looks more-less like this one:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{packageName/YourMainActivity}: java.lang.ClassNotFoundException: YourMainActivity  in loader dalvik.system.PathClassLoader[packageName-1/pkg.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1653)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1755)
at android.app.ActivityThread.access$1500(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1001)
at android.os.Handler.dispatchMessage(Handler.java:130)
at android.os.Looper.loop(SourceFile:351)
at android.app.ActivityThread.main(ActivityThread.java:3822)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:538)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: MainActivity in loader dalvik.system.PathClassLoader[/mnt/asec/packageName-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:271)
at java.lang.ClassLoader.loadClass(ClassLoader.java:582)
at java.lang.ClassLoader.loadClass(ClassLoader.java:542)
at android.app.Instrumentation.newActivity(Instrumentation.java:1056)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1645)
... 11 more


And you think NOOOOO, MY PERFECT APP CANNOT CRASH, WHY? WHY?
Calm down... chill out... take a breath and ... be prepared for bad news.

It is not your fault and there is almost nothing what you can do.Seriously.


SO WHAT I CAN DO?
Ignore it.
Yes.that's answer.
Ignore it.

EXPLANATION OF PROBLEM AND MY LOOSE THOUGHTS

There  are 2 cases:

1) User installed application on sd-card and try to run your application,when
a) sd-card is NOT in device
b) user pluged-in  device via USB to PC/MAC
c) (a bizarre and wierd  rare cases   when user connect to non-PC other device or charger via USB ,but device for whatever reasons, device thinks that is connected to PC.

2) In this case Android decided to install on internal memory,but user uses a third-party application to move your application to the SD card (quite often automatically) .
Problem is that these third-party application  move apps to SD-card in all cases (where Android do not do in some cases that because it guess* correctly that it will not works), where it can cause various problems.
In many cases it will cause "java.lang.RuntimeException: Unable to instantiate activity ComponentInfo" errors as your device cannot find things where they suppose to be. This can happen any time like after install or after update  .
In these cases only Reinstall program is a option.

So... I believe,it is design problem in Android.

I see a easy solution for Android OS to handle this case and explain that user do a bad thing .Android  OS should  capable to know than sd-card is unaccesable , damaged , data was deleted/corrupted or is other sd-card in device(Android OS knows already state of USB,so should be easy to do by folks who making Android OS)  . So instead of crash ,It should inform user:

"Dude! Are you on drugs? SD-card is NOT inserted into f.. device. You need insert sd-card into  device with installed app! So stop drugs and insert sd-card into device and THEN RUN application again."

"You are moron ! WTF are you trying to do? Unplug device from PC to be able to access apps and data stored on sd-card! You CANNOT access to sd-card on device while is used by PC/MAC or whatever piece of junk you are using!"

(It may requires bit better wording due political correctness reasons,but i cleary said that user trying to do something ,which it should NOT! )

I don't know what can be done about second case.
I believe is OS should be response for handle is application not 3rd party apps. As it is important part of OS and for security reasons it should not be accessible by other 3rd party .

How to solve error ?
You CAN'T solve this problem at the moment.
You can ignore it this problem and live with that.
 I hope ,it explains to you . Search for 


* word guess is not a right one. I didn't do deep research about it,so i don't know/remember valuable reasons why this happens.

-------
For users:

Program crashes because:
  1. You connect your device via USB somewhere .
  2. SD-card is not inserted/damaged/used exclusively by other application and block access to other application.
  3. You use application that moves application from internal memory to external memory and screwed-up something. (Problem can appear after you install app,create new shortcut , after update my app or .. randomly for whatever reasons)).


No comments:

Post a Comment