我在developer.android.com中使用下一个教程:
http://developer.android.com/training/camera/photobasics.html
使用API​​ 2.1

  • 当我点击拍一张小照片时,
  • 没问题
  • 当我单击以拍摄一张小照片时,然后单击以一张大照片拍摄,
  • 没问题
  • 但是,当我直接单击大图片时,我拍了一张照片,我的应用程序崩溃了……

  • 在LogCat中:
    05-10 09:26:30.773: D/CameraSample(3407): failed to create directory
    05-10 09:26:33.713: W/IInputConnectionWrapper(3407): showStatusIcon on inactive InputConnection
    05-10 09:26:45.883: I/Parcours(3407): handleBigCameraPhoto
    05-10 09:26:46.133: D/dalvikvm(3407): GC_EXTERNAL_ALLOC freed 124K, 52% free 2628K/5379K, external 1685K/2133K, paused 207ms
    05-10 09:26:46.143: E/dalvikvm-heap(3407): 31961088-byte external allocation too large for this process.
    05-10 09:26:46.163: E/GraphicsJNI(3407): VM won't let us allocate 31961088 bytes
    05-10 09:26:46.213: D/dalvikvm(3407): GC_FOR_MALLOC freed 2K, 52% free 2625K/5379K, external 1685K/2133K, paused 55ms
    05-10 09:26:46.213: D/skia(3407): --- decoder->decode returned false
    05-10 09:26:46.213: D/AndroidRuntime(3407): Shutting down VM
    05-10 09:26:46.223: W/dalvikvm(3407): threadid=1: thread exiting with uncaught exception (group=0x4001d560)
    05-10 09:26:46.223: E/AndroidRuntime(3407): FATAL EXCEPTION: main
    05-10 09:26:46.223: E/AndroidRuntime(3407): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:284)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at rdaquin.apps.takephoto.TakePhotoActivity.setPic(TakePhotoActivity.java:124)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at rdaquin.apps.takephoto.TakePhotoActivity.handleBigCameraPhoto(TakePhotoActivity.java:195)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at rdaquin.apps.takephoto.TakePhotoActivity.onActivityResult(TakePhotoActivity.java:281)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.app.Activity.dispatchActivityResult(Activity.java:3908)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2549)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2595)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.app.ActivityThread.access$2000(ActivityThread.java:121)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.os.Handler.dispatchMessage(Handler.java:99)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.os.Looper.loop(Looper.java:123)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at android.app.ActivityThread.main(ActivityThread.java:3701)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at java.lang.reflect.Method.invokeNative(Native Method)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at java.lang.reflect.Method.invoke(Method.java:507)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
    05-10 09:26:46.223: E/AndroidRuntime(3407):     at dalvik.system.NativeStart.main(Native Method)
    

    如果您需要密码,请问我。

    我不明白为什么我的应用程序崩溃,我认为这是一个内存问题,但是我不知道该怎么办。
    这样,当我“拍摄小图像”和“拍摄大照片”时,它就可以工作。但是,如果我重新加载该应用程序并且我“拍一张照片”不起作用

    最佳答案

    我认为这从堆栈跟踪中可以很明显地看出来,因为您试图在堆上分配32MB,所以内存不足。你不能那样做。不足为奇,因为当您拍摄一张大照片时会发生这种情况。您不能将其存储在内存中。将其写入存储。

    10-07 19:37
    查看更多