返回顶部

OutOfMemory.CN技术专栏-> Java-> OutOfMemoryError全攻略-> android.widget.Gallery.makeAndAddView 内存溢出 FATAL EXCEPTION: main java.lang.OutOfMemoryError

android.widget.Gallery.makeAndAddView 内存溢出 FATAL EXCEPTION: main java.lang.OutOfMemoryError

更多

 如下是我的异常信息:

05-14 15:33:25.336: E/AndroidRuntime(563): FATAL EXCEPTION: main
05-14 15:33:25.336: E/AndroidRuntime(563): java.lang.OutOfMemoryError
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.content.res.Resources.loadDrawable(Resources.java:1937)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.content.res.Resources.getDrawable(Resources.java:664)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.ImageView.resolveUri(ImageView.java:542)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.ImageView.setImageResource(ImageView.java:315)
05-14 15:33:25.336: E/AndroidRuntime(563):  at com.hospital.ImageAdapter.getView(ImageAdapter.java:46)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.makeAndAddView(Gallery.java:844)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.fillToGalleryRightLtr(Gallery.java:798)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.fillToGalleryRight(Gallery.java:742)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.layout(Gallery.java:651)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.Gallery.onLayout(Gallery.java:346)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.View.layout(View.java:11278)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.os.Looper.loop(Looper.java:137)
05-14 15:33:25.336: E/AndroidRuntime(563):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-14 15:33:25.336: E/AndroidRuntime(563):  at java.lang.reflect.Method.invokeNative(Native Method)
05-14 15:33:25.336: E/AndroidRuntime(563):  at java.lang.reflect.Method.invoke(Method.java:511)
05-14 15:33:25.336: E/AndroidRuntime(563):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-14 15:33:25.336: E/AndroidRuntime(563):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-14 15:33:25.336: E/AndroidRuntime(563):  at dalvik.system.NativeStart.main(Native Method)

要解决此问题,需要设置图片的质量,如下代码片段:

BitmapFactory.Options options=new BitmapFactory.Options(); 
options.inSampleSize = 8; 
Bitmap preview_bitmap=BitmapFactory.decodeStream(is,null,options); 

 也可以参考这里: http://stackoverflow.com/a/823966/985143

推荐阅读:
支持

1

反对

0