2013-05-07 177 views
1

我創建了一個完全適用於我的設備的Android應用程序。我已經將APK發送給某人,並且它也在他的設備上工作。Android應用程序崩潰拼圖

有一次,他想修改應用中的某些內容。所以我給他發送了完整的源代碼。

現在他告訴我,源代碼不適用於他。它編譯得很好,但是當它在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} 
+0

看起來像位圖消耗的內存太多。他添加了圖片嗎? – thegrinner 2013-05-07 11:59:28

+0

OutOfMemoryError ..... – Triode 2013-05-07 11:59:52

+0

就是這樣:我的原始源代碼沒有使用任何圖像。他告訴我他現在只是試圖編譯我的源代碼。 – 2013-05-07 12:21:41

回答

0

您所遇到的問題是一個非常常用的一個:你的應用程序運行時內存不足,它試圖爲你是一個位圖分配空間使用。

有一些技巧可以查看Google文檔站點上的Android程序員。例如Managing Bitmap Memory

要避免錯誤,這是一個相當不錯的功能(再次,從谷歌文檔):

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. 調整採樣大小使其適合內存但保持所需的尺寸
0

嘗試增加VM堆內存在AVD爲。

在菜單中選擇 窗口 =>Android虛擬設備管理器 =>選擇AVD您使用=>點擊編輯按鈕。

在舊版本的ADT中。

enter image description here

在ADT的新版本。

enter image description here

當你創建新的AVD需要24 VM堆爲默認值。但是您的應用程序需要更多內存,因此您將其設置爲64.

+0

這不是有點問題嗎?我理解這個問題的方式是,它在實際設備上崩潰,並且無法更改實際設備上的堆參數,對嗎?如果有的話,我會建議他在AVD上配置一個與他的朋友的設備具有相同特徵的圖像,以便他能夠看到他的應用程序崩潰的位置和方式。 – DigCamara 2013-05-07 15:22:50