java.lang.RuntimeException: 无法实例化应用程序 android.app.Application: java.lang.NullPointerException at LoadedApk.makeApplication

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10399789/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:34:25  来源:igfitidea点击:

java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException at LoadedApk.makeApplication

android

提问by OWADVL

So I get this error from time to time. It's at the application launching from the Run button in Eclipse. this occurs once every 4-5 times. Anyone has an idea what's going on.

所以我不时收到这个错误。它位于从 Eclipse 中的“运行”按钮启动的应用程序处。这种情况每 4-5 次发生一次。任何人都知道发生了什么。

I really appreciate it!

对此,我真的非常感激!

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

回答by JRaymond

Looked into the ICS source code - It seems like for whatever reason the Package Manager can't get your package info - it could just be an eclipse/ADT bug where eclipse holds some kind of lock on the file, but whatever it is, it doesn't seem like something that you could cause with your code. I would suggest running a clean, uninstalling the app from the emulator/device, or if those don't work, you might try a fresh eclipse workspace.

查看 ICS 源代码 - 似乎无论出于何种原因,包管理器都无法获取您的包信息 - 这可能只是一个 eclipse/ADT 错误,其中 eclipse 对文件持有某种锁定,但无论如何,它看起来不像是你的代码可能导致的。我建议运行一个干净的,从模拟器/设备卸载应用程序,或者如果这些不起作用,你可以尝试一个新的 eclipse 工作区。

Another thing that might be an issue is if you're using a Library project - try unlinking the two, cleaning, and then linking them back up again - but thats it for my bag o' tricks :)

可能有问题的另一件事是,如果您使用的是图书馆项目 - 尝试断开两者的链接,清理,然后再次将它们链接起来 - 但这就是我的包o'技巧:)

UPDATE:yorkw gives a better explanation for why this occurs and its resolution here: RuntimeException: Unable to instantiate application

更新:yorkw 更好地解释了为什么会发生这种情况及其解决方法:RuntimeException:无法实例化应用程序

回答by Timmmm

This is (unsurprisingly*) a bug in Eclipse/ADT/adb. I managed to fix it by uninstalling my app from the emulator. Hopefully it won't come back, but I'm not going to hold my breath.

这是(不出所料*)Eclipse/ADT/adb 中的一个错误。我设法通过从模拟器卸载我的应用程序来修复它。希望它不会回来,但我不会屏住呼吸。

*Seriously, Eclipse & ADT seem to be the buggiest pieces of software I've ever used. In only one day I've run into at least four different very annoying bugs! (This one, ddms broken pipe, workspace in use but it isn't, dex out of memory.) It's embarrassingly shoddy. Thank god we have stackoverflow!

* 说真的,Eclipse 和 ADT 似乎是我用过的最有缺陷的软件。仅在一天之内,我就遇到了至少四个不同的非常烦人的错误!(这个,ddms 损坏的管道,正在使用的工作区,但它不是,dex 内存不足。)它的劣质令人尴尬。感谢上帝,我们有了 stackoverflow!

Edit: I spoke too soon. The bug returns as soon as you run the app a second time.

编辑:我说得太早了。一旦您第二次运行该应用程序,该错误就会返回。

回答by RicNjesh

I struggled with this error too.The error occurs inconsistently. Found out it was a library dependency that was not included in the build path for API level 16 (android-support-v4)

我也遇到了这个错误。错误发生不一致。发现它是一个库依赖项,未包含在 API 级别 16 (android-support-v4) 的构建路径中

回答by Parmaia

I also get this error when running my app on 4.x or above both emulator and actual device, but the error does not prevent my app to be launched, so I simply ignore it.

在 4.x 或更高版本的模拟器和实际设备上运行我的应用程序时,我也会收到此错误,但该错误不会阻止我的应用程序启动,因此我只是忽略它。

回答by martyglaubitz

It also happens if you're trying to call new Intent(getActivity(), ActivityXY.class)when activity was finished and garabage collected. It's usually an indicator that you forgot to cancel some asynchronous operations when the activity/fragment was destroyed

如果您new Intent(getActivity(), ActivityXY.class)在活动完成并收集垃圾时尝试打电话,也会发生这种情况。这通常是在活动/片段被销毁时忘记取消某些异步操作的指示符

回答by duongvanthai

This is an error from the .projectfile in your project. You can open other .projectfiles on a project without errors for comparison. Almost, you can see wrong with <buildCommand>tag in this file.

这是.project项目中文件的错误。您可以.project在没有错误的情况下打开项目中的其他文件进行比较。几乎,你可以看到<buildCommand>这个文件中的标签有问题。