I want to set large image from drawable into gridview. I have done this code but i got error.

This is my fragment layout name color\_fragment.xml

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/black_overlay">
    <GridView
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:numColumns="3"
        android:columnWidth="90dp"
        android:horizontalSpacing="10dp"
        android:verticalSpacing="10dp"
        android:gravity="center"
        android:stretchMode="columnWidth" >
    </GridView>
</LinearLayout>

```

Here, is my ColorFragment.java Which inflate the above layout

```
public class ColorFragment extends Fragment {
    View view;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.watercolor_fragment, container, false);
        GridView gridView=(GridView)view.findViewById(R.id.gridview);
        gridView.setAdapter(new ImageAdapter(view.getContext()));
        return view;
    }
}

```

Here, is my ImageAdapter

```
public class ImageAdapter extends BaseAdapter {

    private Context context;

    private Integer[] mThumbIds={R.drawable.natureone,R.drawable.naturetwo,
                                 R.drawable.naturethree,R.drawable.naturefour,
                                 R.drawable.naturefive,R.drawable.naturesix,
                                 R.drawable.natureseven,R.drawable.natureight,
            R.drawable.naturenine,R.drawable.natureten,R.drawable.natureleven,R.drawable.naturetwelve,
            R.drawable.naturethrtineen,R.drawable.naturefourthyeen,R.drawable.naturefifteen,R.drawable.naturesixteen,
            R.drawable.natureseventeen,R.drawable.natureone};
    public ImageAdapter(Context context){
        this.context=context;
    }
    @Override
    public int getCount() {
        return mThumbIds.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if(convertView==null){
            imageView=new ImageView(this.context);
            imageView.setLayoutParams(new GridView.LayoutParams(85,85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8,8,8,8);
        }
        else{
            imageView=(ImageView)convertView;
        }
        imageView.setImageResource(mThumbIds[position]);//Got Error here
        return imageView;
    }
}

```

In above code all the images are in HD and it is already exist in xhdpi folder.

I got Error

```
 java.lang.OutOfMemoryError: Failed to allocate a 4798092 byte allocation with 94076 free bytes and 91KB until OOM
                                                     at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
                                                     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
                                                     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:973)
                                                     at android.content.res.Resources.loadDrawableForCookie(Resources.java:2423)
                                                     at android.content.res.Resources.loadDrawable(Resources.java:2330)
                                                     at android.content.res.Resources.getDrawable(Resources.java:758)
                                                     at android.content.Context.getDrawable(Context.java:402)
                                                     at android.widget.ImageView.resolveUri(ImageView.java:741)
                                                     at android.widget.ImageView.setImageResource(ImageView.java:397)
                                                     at com.domore.angelnx.Adapter.ImageAdapter.getView(ImageAdapter.java:63)
                                                     at android.widget.AbsListView.obtainView(AbsListView.java:2344)
                                                     at android.widget.GridView.makeAndAddView(GridView.java:1433)
                                                     at android.widget.GridView.makeRow(GridView.java:361)
                                                     at android.widget.GridView.fillDown(GridView.java:302)
                                                     at android.widget.GridView.fillFromTop(GridView.java:437)
                                                     at android.widget.GridView.layoutChildren(GridView.java:1276)
                                                     at android.widget.AbsListView.onLayout(AbsListView.java:2148)
                                                     at android.view.View.layout(View.java:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     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:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1627)
                                                     at android.view.View.layout(View.java:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     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:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     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:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                                                     at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                                                     at android.view.View.layout(View.java:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435)
                                                     at android.view.View.layout(View.java:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                                                     at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                                                     at android.view.View.layout(View.java:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     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:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
                                                     at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
                                                     at android.view.View.layout(View.java:15596)
                                                     at android.view.ViewGroup.layout(ViewGroup.java:4966)
                                                     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2072)
                                                     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1829)
                                                     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
                                                    at android.view.ViewRootImpl$Tra

```

How to solve this error?
My question is why i got OOM error? Please, help me to solve this error.