当前位置:   article > 正文

android 报错java.lang.outofmemoryerror_Android:java.lang.OutOfMemoryError:无法分配带有2097152个空闲字节的23970828字...

java.lang.outofmemoryerror 安卓 设置运行内存

我想在已存储的SD卡中显示ImageView中的Bitmap图像.运行后我的应用程序崩溃并导致OutOfMemoryError错误:

(java.lang.OutOfMemoryError:无法分配带有2097152个空闲字节的23970828字节分配和2MB直到OOM)

我不知道或为什么它的内存不足.我认为我的图像尺寸非常大,所以我试图改变它.

Iterator it = imageArray.iterator();

while (it.hasNext()) {

Object element = it.next();

String objElement = element.toString();

Log.e("objElement ", " = " + objElement);

final ImageView imageView = new ImageView (getContext());

final ProgressBar pBar = new ProgressBar(getContext(), null,

android.R.attr.progressBarStyleSmall);

imageView.setTag(it);

pBar.setTag(it);

imageView.setImageResource(R.drawable.img_placeholder);

pBar.setVisibility(View.VISIBLE);

if (objElement.endsWith(mp3_Pattern)) {

Log.e("Mp3 ", " ends with ");

pBar.setVisibility(View.GONE);

imageView.setImageResource(R.drawable.audio_control);

}

if (objElement.endsWith(png_Pattern)) {

Bitmap bitmap = BitmapFactory.decodeFile(objElement);

int size = Math.min(bitmap.getWidth(), bitmap.getHeight());

int x = (bitmap.getWidth() - size) / 2;

int y = (bitmap.getHeight() - size) / 2;

Bitmap bitmap_Resul = Bitmap.createBitmap(bitmap, x, y, size, size);

Log.e("bitmap_Resul "," = "+ bitmap_Resul);

if (bitmap_Resul != bitmap) {

bitmap.recycle();

}

imageView.setImageBitmap(bitmap_Resul);

Log.e("png_Pattern ", " ends with ");

Log.e(" bitmap "," = " + bitmap);

}

holder.linearLayout.addView(imageView);

holder.linearLayout.addView(pBar);

日志猫信息:

08-27 14:11:15.307 1857-1857/? E/AndroidRuntime? FATAL EXCEPTION: main

Process: com.example.tazeen.classnkk, PID: 1857

java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM

at dalvik.system.VMRuntime.newNonMovableArray(Native Method)

at android.graphics.Bitmap.nativeCreate(Native Method)

at android.graphics.Bitmap.createBitmap(Bitmap.java:812)

at android.graphics.Bitmap.createBitmap(Bitmap.java:789)

at android.graphics.Bitmap.createBitmap(Bitmap.java:709)

at android.graphics.Bitmap.createBitmap(Bitmap.java:634)

at com.example.tazeen.classnkk.AllPosts_Page$MyListAdapter.getView(AllPosts_Page.java:357)

at android.widget.AbsListView.obtainView(AbsListView.java:2347)

at android.widget.ListView.makeAndAddView(ListView.java:1864)

at android.widget.ListView.fillDown(ListView.java:698)

at android.widget.ListView.fillFromTop(ListView.java:759)

at android.widget.ListView.layoutChildren(ListView.java:1659)

at android.widget.AbsListView.onLayout(AbsListView.java:2151)

at android.view.View.layout(View.java:15671)

at android.view.ViewGroup.layout(ViewGroup.java:5038)

at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)

at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)

at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)

at android.view.View.layout(View.java:15671)

at android.view.ViewGroup.layout(ViewGroup.java:5038)

at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)

at android.widget.FrameLayout.onLayout(FrameLayout.java:514)

at android.view.View.layout(View.java:15671)

at android.view.ViewGroup.layout(ViewGroup.java:5038)

at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)

at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)

at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)

at android.view.View.layout(View.java:15671)

at android.view.ViewGroup.layout(ViewGroup.java:5038)

at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)

at android.widget.FrameLayout.onLayout(FrameLayout.java:514)

at android.view.View.layout(View.java:15671)

at android.view.ViewGroup.layout(ViewGroup.java:5038)

at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)

at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)

at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)

at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)

at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)

at android.view.Choreographer.doCallbacks(Choreographer.java:580)

at android.view.Choreographer.doFrame(Choreographer.java:550)

at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)

at android.os.Handler.handleCallback(Handler.java:739)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:135)

at android.app.ActivityThread.main(ActivityThread.java:5257)

at java.lang.reflect.Method.invoke(Native Method)

at java.lang.reflect.Method.invoke(Method.java:372)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/443802
推荐阅读
相关标签
  

闽ICP备14008679号