OutOfMemoryError android m
Okay, I'm new to Android and have this little problem that I can't seen to find an answer to. I know that this is a common error but all the other threads that I found aren't helpful to me, so I had to create my own.
I'm simply using a listview, and have an Adaptor. The error occurs suddenly when scrolling up and down through the listview items, without even clicking on the items.
Here are some of the logs:
D/OpenGLRenderer: Enabling debug mode 0
D/dalvikvm: GC_FOR_ALLOC freed 173K, 36% free 17008K/26172K, paused 15ms, total 15ms
I/dalvikvm-heap: Grow heap (frag case) to 31.092MB for 10760416-byte allocation
D/AbsListView: unregisterIRListener() is called
D/AbsListView: unregisterIRListener() is called
D/AbsListView: unregisterIRListener() is called
I/dalvikvm-heap: Grow heap (frag case) to 61.836MB for 33177616-byte allocation
D/dalvikvm: GC_FOR_ALLOC freed 52K, 14% free 59979K/69088K, paused 14ms, total 14ms
I/dalvikvm-heap: Grow heap (frag case) to 79.593MB for 18662416-byte allocation
D/dalvikvm: GC_FOR_ALLOC freed 7K, 11% free 78200K/87316K, paused 15ms, total 15ms
I/dalvikvm-heap: Grow heap (frag case) to 111.230MB for 33177616-byte allocation
D/dalvikvm: GC_FOR_ALLOC freed 10515K, 15% free 101867K/119720K, paused 17ms, total 17ms
I/dalvikvm-heap: Forcing collection of SoftReferences for 16104976-byte allocation
D/dalvikvm: GC_BEFORE_OOM freed 15K, 15% free 101851K/119720K, paused 28ms, total 28ms
E/dalvikvm-heap: Out of memory on a 16104976-byte allocation.
.
Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x418ceda0)
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.hesham.assignment2, PID: 24883 java.lang.OutOfMemoryError at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872) at android.content.res.Resources.loadDrawable(Resources.java:3024) at android.content.res.Resources.getDrawable(Resources.java:1586) at android.view.View.setBackgroundResource(View.java:16144) at com.example.hesham.assignment2.myAdaptor.getView(myAdaptor.java:47) at android.widget.AbsListView.obtainView(AbsListView.java:2694) at android.widget.ListView.makeAndAddView(ListView.java:1811) at android.widget.ListView.fillDown(ListView.java:697) at android.widget.ListView.fillGap(ListView.java:661) at android.widget.AbsListView.trackMotionScroll(AbsListView.java:6686) at android.w idget.AbsListView.scrollIfNeeded(AbsListView.java:3946) at android.widget.AbsListView.onTouchMove(AbsListView.java:4789) at android.widget.AbsListView.onTouchEvent(AbsListView.java:4617) at android.view.View.dispatchTouchEvent(View.java:8107) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2129) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2411) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2144) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2411) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2144) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2411) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2144) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2411) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2144) at android.view.ViewGroup.dispatchTransfor medTouchEvent(ViewGroup.java:2411) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2144) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2280) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1615) at android.app.Activity.dispatchTouchEvent(Activity.java:2544) at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2228) at android.view.View.dispatchPointerEvent(View.java:8315) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4598) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4466) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4024) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4078) at android. view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4047) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4158) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4055) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4215) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4024) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4078) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4047) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4055) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4024) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6416) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6320) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6291) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6256) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEve nt(ViewRootImpl.java:649
And there's a an highlighted line, which refers to a line in my Adaptor.
y2.setBackgroundResource(items[i].img);
And here's my whole Adaptor
public class myAdaptor extends BaseAdapter{
Data items[];
Context context;
TextView y;
ImageView y2;
myAdaptor(Data items[], Context context)
{
this.items=items;
this.context=context;
}
@Override
public int getCount() {
return items.length;
}
@Override
public Object getItem(int i) {
return i;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View x=view;
if(x==null)
{
x=View.inflate(context,R.layout.item,null);
}
y=(TextView) x.findViewById(R.id.textView);
y2=(ImageView) x.findViewById(R.id.imageView);
y.setText(items[i].str1);
y2.setBackgroundResource(items[i].img);
return x;
}}
So I can't find why I keep getting this error, and I'm not using a bitmap which I found all the other threads are using. So any ideas on how to fix this? Please let me know if I need to update the thread with any of my code. Sorry for the long post, and thank you.
Try this
Create a folder named drawable-nodpi
inside your res folder . Put all of your images there .
上一篇: 停止活动