Android 运行时异常:无法实例化应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10150899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
RuntimeException: Unable to instantiate application
提问by user182944
When I run my application, everytime I am getting the below exception in my logcat:
当我运行我的应用程序时,每次我在我的 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.access00(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.
注意:当我从模拟器卸载应用程序并运行它时,我没有收到此异常,但是当我在模拟器中重新运行已安装的应用程序时,我得到了这个。请帮忙。
回答by yorkw
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.
这是当 dalvik 重新安装 .apk 文件并尝试从同一包中重用或回收先前打开的活动/视图(如果您尚未关闭先前安装的应用程序)时,底层框架引发的详细错误消息。它与您的应用程序无关,此外,您的应用程序不太可能因最终用户设备上的此详细错误消息而被冻结或崩溃。
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 hereand someone has filled a bug report in Android Issues Tracker.
看来这个dalvik详细错误日志只发生在Android 4.0系统上,我自己在Android 3.2和2.3.3运行环境中测试过,你无法复制以在它们两者上都显示此消息。之前在这里讨论过一个类似的问题,有人在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.
我觉得你现在不应该太在意这个冗长的错误日志,如果你在Logcat中查看这个红色错误前后的更多日志,你可以看到完整的故事,发现之前打开的活动/视图(被标记为死亡状态)被杀死,新安装的一个最终会弹出。
回答by JulianSymes
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.
我意识到这是一个非常古老的问题,但无论如何这可能很有用。我发现当我在自己的开发中观察到这个错误时,这是由于我的应用程序之前运行的实例没有正常关闭,例如在退出之前关闭后台线程。
回答by Ojonugwa Jude Ochalifu
回答by Yoda066
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 threadsolved my problem.
当我尝试在我的应用程序类中使用 JSOUP 连接到互联网时,我遇到了同样的错误。这很棘手,因为应用程序在模拟器上运行而不是在实际设备上运行。原来,我只是用错了 JSOUP 库。在新线程中加载页面解决了我的问题。
Hope I helped someone.
希望我帮助了某人。
回答by stefan96
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
对我来说,它有助于清理项目。在 Eclipse 中:
- Project --> Clean
Please control that Project --> Build Automatically is CHECKED
如果之后 gen-Folder 为空,则 res-folder 中存在错误。通常,红叉不会显示 res 文件夹中的错误!祝你好运和问候
回答by Andrey Uglev
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.
在我的情况下,在我将 Android Maven 项目导入新工作区后出现此错误,并且 SRC 文件夹未自动添加到构建路径。
Right click on the project/Build path/Configure build path/Source - check if there missing sources.
右键单击项目/构建路径/配置构建路径/源 - 检查是否缺少源。
回答by swati
I got the same problem. Uninstalling my app then reinstalling it solved the issue.
我遇到了同样的问题。卸载我的应用程序然后重新安装它解决了这个问题。
回答by Anish
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
文件>无效缓存/重新启动>无效并重新启动
回答by Davi Caetano
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.
我在 (Module:app) build.gradle 文件上将 applicationId 更改为不同的内容,在我的设备上再次运行该应用程序。然后,我撤消更改并再次运行应用程序,一切正常。它适用于 Android Studio 2.3.1 和我在这里拥有的 4 种不同设备,从 5.0 到 7.0。
回答by androidmalin
I meet this question.
When use gradle clean
,gradle installDebug
it work ok!
我遇到这个问题。使用时gradle clean
,gradle installDebug
它工作正常!
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.access00(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