1

我创建了一个可以在我的设备上完美运行的 Android 应用程序。我已将 APK 发送给某人,它也可以在他的设备上运行。

有一次,他想修改应用程序中的某些内容。所以我把完整的源代码发给了他。

现在他告诉我源代码对他不起作用。它编译得很好,但是当它从 Eclipse 中运行它时它会崩溃。

我 100% 确定我已经向他发送了正确的代码,这对我来说很好用。显然没有理由崩溃。

我让他给我发送 logcat 错误,我似乎没有发现问题。

这是(部分):

05-06 08:56:10.954: D/dalvikvm(266): GC_FOR_ALLOC freed 2720K, 13% free 27384K/31239K, paused 40ms, total 42ms
05-06 08:56:11.224: D/dalvikvm(266): GC_FOR_ALLOC freed 4048K, 21% free 24747K/31239K, paused 35ms, total 37ms
05-06 08:56:11.224: I/dalvikvm-heap(266): Forcing collection of SoftReferences for 3785616-byte allocation
05-06 08:56:11.284: D/dalvikvm(266): GC_BEFORE_OOM freed 31K, 21% free 24715K/31239K, paused 54ms, total 54ms
05-06 08:56:11.284: E/dalvikvm-heap(266): Out of memory on a 3785616-byte allocation.
05-06 08:56:11.284: I/dalvikvm(266): "main" prio=5 tid=1 RUNNABLE
05-06 08:56:11.284: I/dalvikvm(266):   | group="main" sCount=0 dsCount=0 obj=0x2bc9b568 self=0x55569be0
05-06 08:56:11.284: I/dalvikvm(266):   | sysTid=266 nice=0 sched=0/0 cgrp=apps handle=716000068
05-06 08:56:11.284: I/dalvikvm(266):   | schedstat=( 4120000000 11950000000 1161 ) utm=335 stm=77 core=0
05-06 08:56:11.294: I/dalvikvm(266):   at android.graphics.Bitmap.nativeCreate(Native Method)
05-06 08:56:11.294: I/dalvikvm(266):   at android.graphics.Bitmap.createBitmap(Bitmap.java:640)
05-06 08:56:11.294: I/dalvikvm(266):   at android.graphics.Bitmap.createBitmap(Bitmap.java:620)
05-06 08:56:11.294: I/dalvikvm(266):   at com.android.launcher2.Cling.dispatchDraw(Cling.java:208)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.View.buildDrawingCache(View.java:12717)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.View.draw(View.java:13154)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.View.draw(View.java:13461)
05-06 08:56:11.294: I/dalvikvm(266):   at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.View.draw(View.java:13342)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2806)
05-06 08:56:11.294: I/dalvikvm(266):   at com.android.launcher2.DragLayer.dispatchDraw(DragLayer.java:743)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.View.draw(View.java:13461)
05-06 08:56:11.294: I/dalvikvm(266):   at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.View.draw(View.java:13342)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.View.draw(View.java:13340)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.View.draw(View.java:13340)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.View.draw(View.java:13461)
05-06 08:56:11.294: I/dalvikvm(266):   at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.294: I/dalvikvm(266):   at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2183)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2258)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewRootImpl.draw(ViewRootImpl.java:2153)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2021)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1832)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.Choreographer.doCallbacks(Choreographer.java:555)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.Choreographer.doFrame(Choreographer.java:525)
05-06 08:56:11.294: I/dalvikvm(266):   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
05-06 08:56:11.294: I/dalvikvm(266):   at android.os.Handler.handleCallback(Handler.java:615)
05-06 08:56:11.294: I/dalvikvm(266):   at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 08:56:11.294: I/dalvikvm(266):   at android.os.Looper.loop(Looper.java:137)
05-06 08:56:11.294: I/dalvikvm(266):   at android.app.ActivityThread.main(ActivityThread.java:4745)
05-06 08:56:11.294: I/dalvikvm(266):   at java.lang.reflect.Method.invokeNative(Native Method)
05-06 08:56:11.294: I/dalvikvm(266):   at java.lang.reflect.Method.invoke(Method.java:511)
05-06 08:56:11.294: I/dalvikvm(266):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-06 08:56:11.294: I/dalvikvm(266):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-06 08:56:11.294: I/dalvikvm(266):   at dalvik.system.NativeStart.main(Native Method)
05-06 08:56:11.294: D/AndroidRuntime(266): Shutting down VM
05-06 08:56:11.294: W/dalvikvm(266): threadid=1: thread exiting with uncaught exception (group=0x2bc9a300)
05-06 08:56:11.334: E/AndroidRuntime(266): FATAL EXCEPTION: main
05-06 08:56:11.334: E/AndroidRuntime(266): java.lang.OutOfMemoryError
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.graphics.Bitmap.nativeCreate(Native Method)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.graphics.Bitmap.createBitmap(Bitmap.java:640)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.graphics.Bitmap.createBitmap(Bitmap.java:620)
05-06 08:56:11.334: E/AndroidRuntime(266):  at com.android.launcher2.Cling.dispatchDraw(Cling.java:208)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.View.buildDrawingCache(View.java:12717)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.View.draw(View.java:13154)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.View.draw(View.java:13461)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.View.draw(View.java:13342)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2806)
05-06 08:56:11.334: E/AndroidRuntime(266):  at com.android.launcher2.DragLayer.dispatchDraw(DragLayer.java:743)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.View.draw(View.java:13461)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.View.draw(View.java:13342)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.View.draw(View.java:13340)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.View.draw(View.java:13340)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.View.draw(View.java:13461)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.334: E/AndroidRuntime(266):  at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2183)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2258)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewRootImpl.draw(ViewRootImpl.java:2153)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2021)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1832)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.Choreographer.doCallbacks(Choreographer.java:555)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.Choreographer.doFrame(Choreographer.java:525)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.os.Handler.handleCallback(Handler.java:615)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.os.Looper.loop(Looper.java:137)
05-06 08:56:11.334: E/AndroidRuntime(266):  at android.app.ActivityThread.main(ActivityThread.java:4745)
05-06 08:56:11.334: E/AndroidRuntime(266):  at java.lang.reflect.Method.invokeNative(Native Method)
05-06 08:56:11.334: E/AndroidRuntime(266):  at java.lang.reflect.Method.invoke(Method.java:511)
05-06 08:56:11.334: E/AndroidRuntime(266):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-06 08:56:11.334: E/AndroidRuntime(266):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-06 08:56:11.334: E/AndroidRuntime(266):  at dalvik.system.NativeStart.main(Native Method)
05-06 08:56:11.346: W/ActivityManager(152):   Force finishing activity com.android.launcher/com.android.launcher2.Launcher
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: W/WindowManager(152): Failure taking screenshot for (266x425) to layer 21005
05-06 08:56:11.954: W/ActivityManager(152): Activity pause timeout for ActivityRecord{2c584740 com.android.launcher/com.android.launcher2.Launcher}
05-06 08:56:11.954: I/ActivityManager(152): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher u=0} from pid 0
05-06 08:56:22.035: W/ActivityManager(152): Activity idle timeout for ActivityRecord{2c57af08 com.android.launcher/com.android.launcher2.Launcher}
4

2 回答 2

0

尝试将AVD中的VM 堆 内存增加到64

在菜单中选择 Window => Android Virtual Device Manager => 选择您使用的avd => 点击编辑按钮。

在旧版本的 ADT 中。

在此处输入图像描述

在新版本的 ADT 中。

在此处输入图像描述

当您创建新的 AVD 时,默认使用 24 个 VM 堆。但是您的应用程序需要更多内存,因此您将其设置为 64。

于 2013-05-07T13:12:15.080 回答
0

您遇到的问题很常见:​​您的应用程序在尝试为您正在使用的位图分配空间时内存不足。

您可以在面向 Android 程序员的 Google 文档站点中查找一些技术。例如管理位图内存

为避免该错误,这是一个非常好的功能(同样来自 Google 文档):

public static int calculateInSampleSize(
            BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {

        // Calculate ratios of height and width to requested height and width
        final int heightRatio = Math.round((float) height / (float) reqHeight);
        final int widthRatio = Math.round((float) width / (float) reqWidth);

        // Choose the smallest ratio as inSampleSize value, this will guarantee
        // a final image with both dimensions larger than or equal to the
        // requested height and width.
        inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
    }

    return inSampleSize;
}

 public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
        int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, resId, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options);
}

什么是:

  1. 验证位图的高度和宽度,而无需将其实际加载到内存中
  2. 调整采样大小,使其适合内存,但保持所需的尺寸
于 2013-05-07T12:00:05.593 回答