24

运行我的应用程序时,有 50% 的时间出现此错误

06-20 12:56:51.183: A/libc(32140): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 32140 (example.www)

我只需要重新打开应用程序,然后它就可以工作了。但我不知道为什么我会收到此错误并且应用程序崩溃。我正在处理尺寸接近 1200x1200 像素的大图像并将其设置为背景。我还将该图像用作其他一些活动的位图作为背景。还对服务器进行一些调用并取回 JSON 数据。希望我提供了足够的信息,因为我不知道要寻找什么...我正在为 4.1.2 开发

完整的 Logcat

   06-20 13:02:38.823: W/ActivityThread(4102): Application eu.sexample.www can be debugged on port 8100...
06-20 13:02:38.983: D/dalvikvm(4102): GC_FOR_ALLOC freed 114K, 7% free 12283K/13191K, paused 13ms, total 13ms
06-20 13:02:38.988: I/dalvikvm-heap(4102): Grow heap (frag case) to 18.398MB for 5954576-byte allocation
06-20 13:02:39.008: D/dalvikvm(4102): GC_CONCURRENT freed 1K, 5% free 18096K/19015K, paused 12ms+1ms, total 22ms
06-20 13:02:39.053: D/dalvikvm(4102): GC_FOR_ALLOC freed 0K, 5% free 18097K/19015K, paused 10ms, total 10ms
06-20 13:02:39.088: I/dalvikvm-heap(4102): Grow heap (frag case) to 41.112MB for 23818256-byte allocation
06-20 13:02:39.103: D/dalvikvm(4102): GC_CONCURRENT freed 0K, 3% free 41357K/42311K, paused 3ms+1ms, total 16ms
06-20 13:02:39.168: D/dalvikvm(4102): GC_FOR_ALLOC freed 5815K, 16% free 35916K/42695K, paused 10ms, total 10ms
06-20 13:02:39.193: E/Location(4102): 51.1878642, 4.3802626
06-20 13:02:39.283: D/libEGL(4102): loaded /system/lib/egl/libEGL_mali.so
06-20 13:02:39.283: D/libEGL(4102): loaded /system/lib/egl/libGLESv1_CM_mali.so
06-20 13:02:39.288: D/libEGL(4102): loaded /system/lib/egl/libGLESv2_mali.so
06-20 13:02:39.288: D/(4102): Device driver API match
06-20 13:02:39.288: D/(4102): Device driver API version: 10
06-20 13:02:39.288: D/(4102): User space API version: 10 
06-20 13:02:39.288: D/(4102): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012 
06-20 13:02:39.323: D/OpenGLRenderer(4102): Enabling debug mode 0
06-20 13:02:42.413: D/dalvikvm(4102): GC_FOR_ALLOC freed 448K, 14% free 37130K/42695K, paused 13ms, total 13ms
06-20 13:02:42.423: I/dalvikvm-heap(4102): Grow heap (frag case) to 42.664MB for 5954576-byte allocation
06-20 13:02:42.433: D/dalvikvm(4102): GC_CONCURRENT freed 4K, 12% free 42941K/48519K, paused 2ms+2ms, total 13ms
06-20 13:02:42.478: D/dalvikvm(4102): GC_FOR_ALLOC freed 0K, 12% free 42941K/48519K, paused 10ms, total 10ms
06-20 13:02:42.478: I/dalvikvm-heap(4102): Forcing collection of SoftReferences for 23818256-byte allocation
06-20 13:02:42.498: D/dalvikvm(4102): GC_BEFORE_OOM freed 9K, 12% free 42931K/48519K, paused 19ms, total 19ms
06-20 13:02:42.498: E/dalvikvm-heap(4102): Out of memory on a 23818256-byte allocation.
06-20 13:02:42.498: I/dalvikvm(4102): "main" prio=5 tid=1 RUNNABLE
06-20 13:02:42.498: I/dalvikvm(4102):   | group="main" sCount=0 dsCount=0 obj=0x41585508 self=0x415758c8
06-20 13:02:42.498: I/dalvikvm(4102):   | sysTid=4102 nice=0 sched=0/0 cgrp=apps handle=1074532144
06-20 13:02:42.498: I/dalvikvm(4102):   | schedstat=( 2709445063 154759556 1906 ) utm=227 stm=43 core=2
06-20 13:02:42.498: I/dalvikvm(4102):   at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-20 13:02:42.498: I/dalvikvm(4102):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:623)
06-20 13:02:42.498: I/dalvikvm(4102):   at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:476)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.content.res.Resources.loadDrawable(Resources.java:1963)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.view.View.<init>(View.java:3436)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.view.View.<init>(View.java:3371)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.view.ViewGroup.<init>(ViewGroup.java:426)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.widget.RelativeLayout.<init>(RelativeLayout.java:184)
06-20 13:02:42.503: I/dalvikvm(4102):   at java.lang.reflect.Constructor.constructNative(Native Method)
06-20 13:02:42.503: I/dalvikvm(4102):   at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-20 13:02:42.508: I/dalvikvm(4102):   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-20 13:02:42.508: I/dalvikvm(4102):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.Activity.setContentView(Activity.java:1924)
06-20 13:02:42.508: I/dalvikvm(4102):   at eu.sexample.www.MainActivity.onCreate(MainActivity.java:28)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.Activity.performCreate(Activity.java:5206)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread.access$600(ActivityThread.java:140)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.os.Looper.loop(Looper.java:137)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread.main(ActivityThread.java:4898)
06-20 13:02:42.508: I/dalvikvm(4102):   at java.lang.reflect.Method.invokeNative(Native Method)
06-20 13:02:42.508: I/dalvikvm(4102):   at java.lang.reflect.Method.invoke(Method.java:511)
06-20 13:02:42.513: I/dalvikvm(4102):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
06-20 13:02:42.513: I/dalvikvm(4102):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
06-20 13:02:42.513: I/dalvikvm(4102):   at dalvik.system.NativeStart.main(Native Method)
06-20 13:02:42.513: A/libc(4102): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 4102 (example.www)
4

3 回答 3

34

真正的错误是Out of memory on a 23818256-byte allocation。您正在尝试分配约 22MB 的内存块,但您没有那么多可用内存,更不用说这么大的连续块了。

在这种情况下,这来自可绘制资源。~22MB 将是一个真正巨大的图像,更像是 2400x2400 而不是 1200x1200。

您的进程堆大小为 48MB,这是相当大的,但 ~22MB 几乎是您的堆预算的一半。

我建议您找出这是哪个可绘制资源(看起来可能是 a 的背景RelativeLayout),然后减小它的大小和类似图像的大小。在这里,“大小”是指总像素数,而不是磁盘大小,因为重要的是 RAM 中的解压缩大小,而不是图像在磁盘上的大小。

此外,这可能是资源目录的问题。例如,如果您将 1200x1200 图像放入 中res/drawable/,那实际上就是 . 的同义词res/drawable-mdpi/。如果这个设备恰好是一个-xhdpi设备,那么这将解释内存使用情况,因为 Android 将尝试对该图像进行上采样并将每个尺寸加倍。

于 2013-06-20T12:19:50.503 回答
3

在你的 AndroidMenifest 中。

<application.... android:hardwareAccelerated="false" />

为我工作。

于 2017-08-30T13:46:37.683 回答
0

Replace FrameLayout with LinearLayout in XML layout

于 2020-03-26T18:44:51.127 回答