2013-05-07 2 views
1

J'ai créé une application Android qui fonctionne parfaitement sur mon appareil. J'ai envoyé l'APK à quelqu'un, et cela a fonctionné sur son appareil aussi. À un moment donné, il voulait modifier quelque chose dans l'application. Donc je l'ai envoyé sur le code source complet.Crash de l'application Android

Maintenant, il me dit que le code source ne fonctionne pas pour lui. Il compile bien, mais quand il l'exécute depuis Eclipse, il se bloque.

Je suis sûr à 100% que je lui ai envoyé le bon code, ça marche très bien pour moi. Apparemment, il n'y a pas de raison pour le crash. Je lui ai demandé de m'envoyer les erreurs logcat et je n'ai pas l'air de trouver le problème.

Ici, il est (en partie):

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

On dirait qu'un bitmap consomme trop de mémoire. A-t-il ajouté des images? – thegrinner

+0

OutOfMemoryError ..... – Triode

+0

Voilà la chose: mon code source original n'utilisait aucune image. Et il m'a dit qu'il essayait juste de compiler mon code source pour le moment. –

Répondre

0

Le problème que vous rencontrez est une jolie habitude un: votre application est en cours d'exécution de mémoire quand il essaie d'allouer l'espace pour une Bitmap que vous êtes en utilisant.

Il existe des techniques que vous pouvez rechercher sur le site de documentation Google pour les programmeurs Android. Par exemple Managing Bitmap Memory.

Pour éviter l'erreur, c'est une fonction assez bon (encore une fois, de Google docs):

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); 
} 

Ce qui est fait est:

  1. Vérifiez la hauteur et la largeur de votre Bitmap sans en fait le charger dans la mémoire
  2. Ajuster la taille d'échantillonnage pour qu'elle tienne dans la mémoire, mais conserve les dimensions requises
0

Essayez d'augmenter VM Heapmémoire dans AVD comme .

Dans le menu, sélectionnez Fenêtre =>périphérique virtuel Android Gestionnaire => sélectionnez AVD que vous utilisez => cliquez sur le bouton modifier .

Dans l'ancienne version d'ADT.

enter image description here

Dans la nouvelle version d'ADT.

enter image description here

Lorsque vous créez AVD, il prend 24 VM Heap par défaut. mais votre application a besoin de plus de mémoire donc, vous le définissez comme 64.

+0

N'est-ce pas un peu problématique? La façon dont je comprends la question, il plantage sur un appareil réel et vous ne pouvez pas modifier les paramètres du tas sur les dispositifs réels, pouvez-vous? Si quelque chose, je lui conseille de configurer une image sur AVD qui a les mêmes caractéristiques de l'appareil de ses amis afin qu'il puisse voir où et comment son application plante. – DigCamara