RuntimeException: Unable to instantiate applicatio

2018-12-31 21:51发布

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.

12条回答
查无此人
2楼-- · 2018-12-31 22:09

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.

查看更多
有味是清欢
3楼-- · 2018-12-31 22:12

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

查看更多
春风洒进眼中
4楼-- · 2018-12-31 22:12

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
查看更多
旧人旧事旧时光
5楼-- · 2018-12-31 22:21

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.

查看更多
墨雨无痕
6楼-- · 2018-12-31 22:21

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

查看更多
旧时光的记忆
7楼-- · 2018-12-31 22:22

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.

查看更多
登录 后发表回答