君不见长松卧壑困风霜,时来屹立扶明堂。这篇文章主要讲述获得此异常会强制Android应用程序在启动时崩溃相关的知识,希望能为你提供帮助。
11-23 10:38:04.430 2095-2095/? I/art: Not late-enabling -Xcheck:jni (already on) 11-23 10:38:04.430 2095-2095/? I/art: Late-enabling JIT 11-23 10:38:04.433 2095-2095/? I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000 11-23 10:38:04.830 2095-2095/com.example.somanshusrivastava.carpiko W/System: ClassLoader referenced unknown path: /data/app/com.example.somanshusrivastava.carpiko-2/lib/x86 11-23 10:38:05.697 2095-2106/com.example.somanshusrivastava.carpiko I/art: Background partial concurrent mark sweep GC freed 96(3KB) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 2.581ms total 140.616ms 11-23 10:38:05.812 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.812 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.827 2095-2095/com.example.somanshusrivastava.carpiko I/art: Alloc sticky concurrent mark sweep GC freed 79(11KB) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 5.901ms total 13.614ms 11-23 10:38:05.836 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.850 2095-2095/com.example.somanshusrivastava.carpiko I/art: Alloc partial concurrent mark sweep GC freed 23(1008B) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 2.153ms total 10.247ms 11-23 10:38:05.853 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.867 2095-2095/com.example.somanshusrivastava.carpiko I/art: Alloc concurrent mark sweep GC freed 15(12KB) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 1.431ms total 13.789ms 11-23 10:38:05.868 2095-2095/com.example.somanshusrivastava.carpiko I/art: Forcing collection of SoftReferences for 49MB allocation 11-23 10:38:05.869 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.881 2095-2095/com.example.somanshusrivastava.carpiko I/art: Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 1.407ms total 11.758ms 11-23 10:38:05.882 2095-2095/com.example.somanshusrivastava.carpiko W/art: Throwing OutOfMemoryError "Failed to allocate a 51750048 byte allocation with 4194304 free bytes and 13MB until OOM" 11-23 10:38:05.882 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.882 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.892 2095-2095/com.example.somanshusrivastava.carpiko I/art: Alloc sticky concurrent mark sweep GC freed 3(608B) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 1.389ms total 8.964ms 11-23 10:38:05.894 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.903 2095-2095/com.example.somanshusrivastava.carpiko I/art: Alloc partial concurrent mark sweep GC freed 6(192B) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 1.387ms total 8.867ms 11-23 10:38:05.904 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.916 2095-2095/com.example.somanshusrivastava.carpiko I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 1.416ms total 10.922ms 11-23 10:38:05.917 2095-2095/com.example.somanshusrivastava.carpiko I/art: Forcing collection of SoftReferences for 49MB allocation 11-23 10:38:05.917 2095-2095/com.example.somanshusrivastava.carpiko I/art: Starting a blocking GC Alloc 11-23 10:38:05.928 2095-2095/com.example.somanshusrivastava.carpiko I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 7% free, 50MB/54MB, paused 1.350ms total 10.018ms 11-23 10:38:05.929 2095-2095/com.example.somanshusrivastava.carpiko W/art: Throwing OutOfMemoryError "Failed to allocate a 51750048 byte allocation with 4194304 free bytes and 13MB until OOM" 11-23 10:38:05.929 2095-2095/com.example.somanshusrivastava.carpiko D/skia: --- allocation failed for scaled bitmap 11-23 10:38:05.930 2095-2095/com.example.somanshusrivastava.carpiko D/androidRuntime: Shutting down VM 11-23 10:38:05.930 2095-2095/com.example.somanshusrivastava.carpiko E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.somanshusrivastava.carpiko, PID: 2095 java.lang.OutOfMemoryError: Failed to allocate a 51750048 byte allocation with 4194304 free bytes and 13MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080) at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635) at android.content.res.Resources.loadDrawable(Resources.java:2540) at android.content.res.TypedArray.getDrawable(TypedArray.java:870) at android.widget.ImageView.(ImageView.java:152) at android.widget.ImageView.(ImageView.java:140) at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:58) at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:54) at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:95) at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938) at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992) at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) at com.example.somanshusrivastava.carpiko.MainActivity.onCreate(MainActivity.java:24) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 11-23 10:38:07.560 2095-2102/com.example.somanshusrivastava.carpiko W/art: Suspending all threads took: 13.233ms 11-23 10:38:09.537 2095-2102/com.example.somanshusrivastava.carpiko W/art: Suspending all threads took: 9.664ms 11-23 10:38:11.140 2095-2095/? I/Process: Sending signal. PID: 2095 SIG: 9
每当我尝试运行AVD时,我的应用程序意外关闭,这就是我得到的错误。这是生成的logcat。它显示FatalException和MemoryException。是AVD错误还是代码错误?请帮忙。
答案您需要了解位图和内存的概念
假设您想要在屏幕上显示刚用相机拍摄的图像。使用以下公式计算所需的总内存:memory_needed_in_bytes = 4 * image_width * image_height;另一答案抛出的异常被称为
为什么4?嗯,最常见/推荐的位图配置是ARGB_8888。这意味着对于我们绘制的每个像素,我们需要为内存中的alpha,红色,贪婪和蓝色通道保留8位(1个字节),以便正确显示它。有一些替代品,比如RGB_565配置需要一半的内存而不是ARGB_8888,但是会失去透明度和颜色精度(同时可能会增加绿色)。
让我们假设你有一个全高清屏幕和12万像素摄像头的全新设备。您刚刚拍摄的图片大小为4000x3000像素,显示所需的总内存为:4字节* 4000 * 3000 = 48 MB
对于单个图像,48兆字节的RAM!?好多啊!
现在让我们考虑屏幕分辨率。您试图在具有1920x1080像素的屏幕上显示4000x3000图像,在最坏的情况下(显示图像全屏),您不应分配超过4 * 1920 * 1080 = 8.3 MB的内存。
始终遵循有效显示位图的Android编程技巧:
测量您正在显示图像的视图。相应地缩放/裁剪大图像。仅显示可显示的内容。
OutOfMemoryError
。当(显然)你的内存不足时会发生错误!这是它的文档:在使用可用平台资源无法满足内存请求时抛出。这样的请求可以由正在运行的应用程序或VM的内部功能来进行。更多信息:
http://developer.android.com/reference/java/lang/OutOfMemoryError.html
因此,您应该为模拟器分配更多内存。但我认为主要原因是你的应用程序使用了太多内存。你使用超大图像了吗?
另一答案【获得此异常会强制Android应用程序在启动时崩溃】将此ligne添加到清单文件中:
android:largeHeap="true"
推荐阅读
- Android模拟器不会关闭
- create react native app expo无法连接在同一台计算机上的模拟器上运行
- (如何)Android虚拟设备可以使用本地计算机的互联网吗()
- Android Webview Back按钮适用于模拟器,但不适用于设备
- Android Studio模拟器快照错误
- Android Emulator警告来宾不在线 - 如何关闭新的快速启动功能()
- 如何在Android模拟器中将应用程序的快捷方式添加到主屏幕
- 如何在android avd命令行中选择文本输入()
- 模拟器(模拟器:警告:UpdateCheck:失败:android studio 3.0.1上的错误问题)