RuntimeException: Unable to instantiate application
Asked Answered
B

14

104

When I run my application, everytime I am getting the below exception in my logcat:

 04-14 09:29:53.965: W/dalvikvm(1020): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
    04-14 09:29:53.985: E/AndroidRuntime(1020): FATAL EXCEPTION: main
    04-14 09:29:53.985: E/AndroidRuntime(1020): java.lang.RuntimeException: Unable to instantiate application   android.app.Application: java.lang.NullPointerException
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.app.ActivityThread.access$1300(ActivityThread.java:123)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.os.Handler.dispatchMessage(Handler.java:99)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.os.Looper.loop(Looper.java:137)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.app.ActivityThread.main(ActivityThread.java:4424)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at java.lang.reflect.Method.invokeNative(Native Method)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at java.lang.reflect.Method.invoke(Method.java:511)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at dalvik.system.NativeStart.main(Native Method)
    04-14 09:29:53.985: E/AndroidRuntime(1020): Caused by: java.lang.NullPointerException
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
    04-14 09:29:53.985: E/AndroidRuntime(1020):     ... 11 more

Note: When I uninstall the app from the emulator and run it, then I don't get this exception but when I re-run the installed application in emulator, I am getting this. Please help.

Broadcasting answered 14/4, 2012 at 4:5 Comment(6)
if your package is android.app.Application ,try changing the package name ,kinda looks suspicious , looks like System's package.Cachalot
Also make sure you app is declared in the Manifest.Differentia
Expand out the Caused by: java.lang.NullPointerException line. There should be a reference to a line in your application further down the lineAran
No,I don't have any package like you mentioned in my application. App is declared in the Manifest as: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.infy.meetingmanager.activity" android:versionCode="1" android:versionName="1.0" > <application...> <activity android:name=".LoginActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />Broadcasting
Which Android version is your app running on, 4.0?Schematism
android:versionCode="1" android:versionName="1.0" <uses-sdk android:minSdkVersion="15" />Broadcasting
S
195

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.

Schematism answered 14/4, 2012 at 23:31 Comment(11)
Hi, No my app is neither crashed nor freezed because of that exception, Its working fine even after the exception is thrown. I just saw the exception in the logcat and was unaware of it, hence thought of asking the same. Thanks for the info, a very useful one.Broadcasting
I'm getting this in the developer console of a production application. It seems to primarily happen with 4.2, but I've seen other version as well (4.1, 4.4).Stratagem
@Dustin, did you solved this? As this exceptions reports at most 34/week! and a lot of complains in user messages!Sewell
Same here @Stratagem Any Solution?Jounce
I'm still getting it locally in Android 5.1.1.Xenogamy
I was using KitKat (4.4.2) but there was no such error. It started to appear on Lollipop (5.1.1).Aleksandrovsk
It occurs even on 5.1.1 . What is going on?Kinship
I tried to restart android studio (1.3.1) and run again on my device, now its working fine, this might be a bug of some sort, dunno what triggers it.Discerning
Sorry for reviving an old thread, but this occurred in the cloud test lab on play console alpha release.. What guarantee is there that this won't occur on production and the user upgrades the app and faces this. :(Biserrate
on 5.1 and 6.0 I'm seeing smth similar caused by IllegalStateExceptionMoncear
I actually still see it on old Android versions(on both devices and emulators), and I have latest version of IDE and gradle...Kinship
M
16

I realise it's a very old question, but this may be useful anyway. I've found that when I observe this error in my own development, it's due to the previously running instance of my app not closing down neatly, for example by shutting down background threads prior to exit.

Mercedes answered 17/7, 2013 at 17:44 Comment(3)
Yes hitting the home button on my phone then running this again removes this error for me as well.Kalisz
Makes sense, but how can an app close down neatly when it's open in front of the user and then Android kills it to upgrade it?Xenogamy
Presumably Android invokes onDestroy() methods in that scenario, no? One would hope so.Mercedes
B
2

I have been getting same error when I tried connect to the internet with JSOUP inside my application class. It was tricky, because application run on emulator but not on actual device. It turned out, that I just used JSOUP library wrong. Loading page in new thread solved my problem.

Hope I helped someone.

Burner answered 25/7, 2014 at 20:43 Comment(0)
B
2

Hope this helps someone. Go to the running apps on your emulator by clicking this:

enter image description here

enter image description here

Close the app you are trying to install and then run it again. NO need to uninstall/reinstall app or clean project.

Bibby answered 18/2, 2016 at 17:4 Comment(0)
L
1

For me it helped to clean the Project. In Eclipse:
- Project --> Clean
Please control that Project --> Build Automatically is CHECKED
If the gen-Folder is empty after that, there's a mistake in the res-folder. Often, mistakes in the res-folder aren't shown by the red cross! Good luck and greetings

Lamb answered 5/5, 2014 at 15:45 Comment(1)
Didn't help for me. When I use adb to upgrade from one of my production apks to another, this problem happens, so it doesn't seem specific to the IDE in my case.Xenogamy
D
1

Simple Solution:

Just Restart your emulator or mobile device. And the problem is gone! Reason for this issue was due to a previous app activity was wrongly halted.

Detestation answered 14/2, 2020 at 7:19 Comment(0)
G
1

I received this error when using ksp instead of kapt when adding hilt dependency

Change

ksp "com.google.dagger:hilt-compiler:$hilt_verson"

to

kapt "com.google.dagger:hilt-compiler:$hilt_verson"

Hope that helps

Gorges answered 25/1, 2023 at 6:45 Comment(0)
S
0

In my case this error appear after I've imported Android Maven project into new workspace, and SRC folder was not automatically added to build path.

Right click on the project/Build path/Configure build path/Source - check if there missing sources.

Swaggering answered 4/6, 2014 at 10:1 Comment(0)
C
0

I got the same problem. Cleaning the project worked for me.

Select project go to Project --> Clean

Corfam answered 15/11, 2014 at 4:58 Comment(1)
Didn't help for me. When I use adb to upgrade from one of my production apks to another, this problem happens, so it doesn't seem specific to the IDE in my case.Xenogamy
C
0

In my case logcat show me it coudn't find the initial activity, but the Dex Path was different, it was ".../data/app/myapp-1" instead of ".../data/app/myapp". I soved this making click on the elcipse project name "myapp" in the Package explorer window. Then right click on it, ->refactor->rename... I set the project name to myapp-1, and then, ->refactor->rename... and back again to "myapp". Then it worked... some kinf of bug in eclipse?

Compton answered 23/7, 2015 at 13:24 Comment(0)
P
0

I got the same problem. Uninstalling my app then reinstalling it solved the issue.

Precancel answered 17/6, 2016 at 4:47 Comment(0)
T
0

I experienced this when I imported my project which was built from a different machine. Just Invalidate caches and restart

File>Invalidate Caches/Restart>Invalidate and restart

Trefoil answered 27/3, 2017 at 6:29 Comment(0)
P
0

I changed the applicationId to something different on (Module:app) build.gradle file, run the app again on my device. Then, I undo the change and run the app again and everything works. It works on Android Studio 2.3.1 and 4 different devices I have here, from 5.0 to 7.0.

Petrarch answered 10/4, 2017 at 18:39 Comment(0)
K
0

I meet this question. When use gradle clean,gradle installDebug it work ok!

   AndroidRuntime  D  Shutting down VM
E  FATAL EXCEPTION: main
E  Process: tv.panda.live.broadcast, PID: 4685
E  java.lang.RuntimeException: Unable to instantiate application tv.panda.live.broadcast.PandaApplication: java.lang.ClassNotFoundException: Didn't find class "tv.panda.live.broadcast.PandaApplication" o
   n path: DexPathList[[zip file "/data/app/tv.panda.live.broadcast-1/base.apk"],nativeLibraryDirectories=[/data/app/tv.panda.live.broadcast-1/lib/arm, /vendor/lib, /system/lib]]
E      at android.app.LoadedApk.makeApplication(LoadedApk.java:572)
E      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4883)
E      at android.app.ActivityThread.access$1500(ActivityThread.java:178)
E      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1573)
E      at android.os.Handler.dispatchMessage(Handler.java:111)
E      at android.os.Looper.loop(Looper.java:194)
E      at android.app.ActivityThread.main(ActivityThread.java:5691)
E      at java.lang.reflect.Method.invoke(Native Method)
E      at java.lang.reflect.Method.invoke(Method.java:372)
E      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
E      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
E  Caused by: java.lang.ClassNotFoundException: Didn't find class "tv.panda.live.broadcast.PandaApplication" on path: DexPathList[[zip file "/data/app/tv.panda.live.broadcast-1/base.apk"],nativeLibraryDi
   rectories=[/data/app/tv.panda.live.broadcast-1/lib/arm, /vendor/lib, /system/lib]]
E      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E      at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E      at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E      at android.app.Instrumentation.newApplication(Instrumentation.java:988)
E      at android.app.LoadedApk.makeApplication(LoadedApk.java:567)
E      ... 10 more
E      Suppressed: java.lang.ClassNotFoundException: tv.panda.live.broadcast.PandaApplication
E          at java.lang.Class.classForName(Native Method)
E          at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E          at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E          at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E          ... 13 more
E      Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Kizzee answered 4/12, 2017 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.