Showing posts with label AndroidException. Show all posts
Showing posts with label AndroidException. Show all posts

Sunday, November 25, 2012

RuntimeException: Unable to instantiate application [ANDROID]

When I run the Android app in Eclipse IDE I'm getting below exception in LogCat,


11-25 11:15:28.252: E/AndroidRuntime(19850): FATAL EXCEPTION: main
11-25 11:15:28.252: E/AndroidRuntime(19850): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3949)
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.app.ActivityThread.access$1300(ActivityThread.java:127)
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.os.Looper.loop(Looper.java:137)
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.app.ActivityThread.main(ActivityThread.java:4511)
11-25 11:15:28.252: E/AndroidRuntime(19850): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 11:15:28.252: E/AndroidRuntime(19850): at java.lang.reflect.Method.invoke(Method.java:511)
11-25 11:15:28.252: E/AndroidRuntime(19850): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
11-25 11:15:28.252: E/AndroidRuntime(19850): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
11-25 11:15:28.252: E/AndroidRuntime(19850): at dalvik.system.NativeStart.main(Native Method)
11-25 11:15:28.252: E/AndroidRuntime(19850): Caused by: java.lang.NullPointerException
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
11-25 11:15:28.252: E/AndroidRuntime(19850): at android.app.LoadedApk.makeApplication(LoadedApk.java:474)

Solution: [From StackOverlow]


This is a verbose error message raised by underlying framework when dalvik re-install .apk file and trying to reuse or recycle the previous opened activity/view from the same package.. if you haven't closed the previous installed app yet). It has nothing to do with your app, moreover, it is very unlikely that your app will get freezed or crashed cause by this verbose error message on end user's device.
It seems that this dalvik verbose error log only happend on Android 4.0 system, I've tested it myself on Android 3.2 and 2.3.3 running environment, where you cannot replicate to get this message shown on neither of them. A similar question has been discussed before at here and someone has filled a bug report in Android Issues Tracker.
I don't think you should concern too much about this verbose error log at the moment, if you look more logs before and after this red error in Logcat, you can see the full story and find that the previous opened activity/view (which are marked as died state) get killed and the newly re-installed one get poped ultimately.

Saturday, November 17, 2012

android.os.NetworkOnMainThreadException



android.os.NetworkOnMainThreadException exception in Android code??

This exception is thrown when an application attempts to perform a networking operation on its main thread.. 

If your code works in Android 2.x but throws this exception on Android 3.0 and above is because HoneyComb, Ice Cream Sandwich, JellyBean are much stricter about abuse against the UI Thread.. To prevent this exception you need to run the same code in ASyncTask..


The explanation as to why this exception occurs is well documented on the Android developer's site:

A NetworkOnMainThreadException is thrown when an application attempts to perform a networking operation on its main thread. This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged.