java.lang.OutOfMemoryError: bitmap size exceeds VM budget in android
<p>i have an android application and i load some data from my local server to my android app. it also load some images from server to a custom ListView  but when i start my app and go to the that Listview then i got error</p>

<pre><code>05-15 04:18:16.146: E/dalvikvm-heap(1290): 1920000-byte external allocation too large for this process.
05-15 04:18:16.277: I/dalvikvm-heap(1290): Clamp target GC heap from 32.072MB to 32.000MB
05-15 04:18:16.277: E/GraphicsJNI(1290): VM won't let us allocate 1920000 bytes
05-15 04:18:16.286: D/dalvikvm(1290): GC_FOR_MALLOC freed &lt;1K, 50% free 2836K/5639K, external 25352K/25754K, paused 58ms
05-15 04:18:16.286: D/skia(1290): --- decoder-&gt;decode returned false
05-15 04:18:16.286: D/AndroidRuntime(1290): Shutting down VM
05-15 04:18:16.286: W/dalvikvm(1290): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-15 04:18:16.306: E/AndroidRuntime(1290): FATAL EXCEPTION: main
05-15 04:18:16.306: E/AndroidRuntime(1290): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:326)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.graphics.drawable.Drawable.createFromStream(Drawable.java:657)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at com.comsats.restaurantandroid.activity.DishListBaseAdapter.LoadImageFromWebOperations(DishListBaseAdapter.java:223)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at com.comsats.restaurantandroid.activity.DishListBaseAdapter.getView(DishListBaseAdapter.java:193)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.widget.AbsListView.obtainView(AbsListView.java:1418)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.widget.ListView.onMeasure(ListView.java:1127)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.view.View.measure(View.java:8313)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.view.View.measure(View.java:8313)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.view.View.measure(View.java:8313)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.view.View.measure(View.java:8313)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.os.Looper.loop(Looper.java:123)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at android.app.ActivityThread.main(ActivityThread.java:3647)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at java.lang.reflect.Method.invokeNative(Native Method)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at java.lang.reflect.Method.invoke(Method.java:507)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-15 04:18:16.306: E/AndroidRuntime(1290):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>here is my java files</p>

<p><strong>HotdishesList.java</strong></p>

<pre><code> package com.comsats.restaurantandroid.activity;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.comsats.restaurantandroid.DishDetails;
import com.comsats.restaurantandroid.R;
import com.comsats.restaurantandroid.store.OrderStore;
import com.comsats.restaurantandroid.util.URLConnectionReader;


public class HotDishesList extends ApplicationMenu implements TextWatcher {

    EditText searchDish;
    DishListBaseAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dishes_main);

        ArrayList&lt;DishDetails&gt; dish_details = GetSearchResults();

        ImageView backBtn = (ImageView) findViewById(R.id.backBtn);
        ImageView homeBtn = (ImageView) findViewById(R.id.homeBtn);
        TextView headerTxt = (TextView) findViewById(R.id.headertext); 

        //TextView Txt = (TextView) findViewById(R.id.text);
        //  top order bar
        RelativeLayout top_bar = (RelativeLayout) findViewById(R.id.top_order_bar);
        TextView top_order_txt = (TextView) findViewById(R.id.text_order);

        top_bar.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
                Intent ourIntent = new Intent(HotDishesList.this, Order.class);
                HotDishesList.this.startActivity(ourIntent);
            }
        });

        if(OrderStore.getCart().isEmpty())
        {

        }
        else
        {
            top_order_txt.setText(OrderStore.getCart().size()+" item(s) added.");
            top_bar.setVisibility(0);
        }

        final ListView dishesList = (ListView) findViewById(R.id.dishesList);
        adapter = new DishListBaseAdapter(this, dish_details,"hot");

        headerTxt.setText("Hot Dishes");

        backBtn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
                Intent ourIntent = new Intent(HotDishesList.this, Home.class);
                HotDishesList.this.startActivity(ourIntent);
            }
        });
        homeBtn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
                Intent ourIntent = new Intent(HotDishesList.this, Home.class);
                HotDishesList.this.startActivity(ourIntent);
            }
        });

        if(dish_details.size() &gt; 0)
        {

              dishesList.setAdapter(adapter);
        }
        else
        {
            Toast.makeText(getApplicationContext(), "No Hot Dishes Found!", Toast.LENGTH_LONG).show();
        }


        dishesList.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) {
                Object o = dishesList.getItemAtPosition(position);
                DishDetails obj_itemDetails = (DishDetails)o;
                final Bundle basket = new Bundle();
                basket.putString("checkDish", "hot");
                basket.putString("dishID", String.valueOf(obj_itemDetails.getDishID()));
                basket.putString("dishCategory", String.valueOf(obj_itemDetails.getDishCategory()));
                basket.putString("dishName", obj_itemDetails.getDishName());
                basket.putString("dishDescription", obj_itemDetails.getDishDescription());
                basket.putString("dishPrice", obj_itemDetails.getDishPrice());
                basket.putString("dishCalories", obj_itemDetails.getDishCalories());
                basket.putString("dishDiscount", obj_itemDetails.getDishDiscount());
                basket.putString("dishCookTime", obj_itemDetails.getDishCookTime());
                basket.putString("dishImage", obj_itemDetails.getDishImage());
                basket.putString("dishUnit", obj_itemDetails.getDishUnit());
                basket.putString("dishStatus", obj_itemDetails.getDishStatus());

                Thread timer = new Thread()
                {
                    public void run(){
                            try{
                                Intent ourIntent = new Intent(HotDishesList.this, Loading.class);
                                HotDishesList.this.startActivity(ourIntent);
                                sleep(1000);

                            }catch (Exception e) {
                                // TODO: handle exception
                            }finally{
                                try {
                                    @SuppressWarnings("rawtypes")
                                    Class ourClass = Class.forName("com.comsats.restaurantandroid.activity.DishDetail");
                                    finish();
                                    Intent ourIntent = new Intent(HotDishesList.this, ourClass);
                                    ourIntent.putExtras(basket);
                                    HotDishesList.this.startActivity(ourIntent);
                                } catch (ClassNotFoundException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                } 
                            }
                    }
                };
            timer.start();

            }
        }); 

        searchDish = (EditText) findViewById(R.id.search_dish);
        searchDish.setHint("Search Hot Dish");
        searchDish.addTextChangedListener(this);
    }

    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        // TODO Auto-generated method stub

    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub

    }

    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
        String text = searchDish.getText().toString().toLowerCase();
        adapter.filter(text);
    }



    public ArrayList&lt;DishDetails&gt; GetSearchResults(){
        ArrayList&lt;DishDetails&gt; results = new ArrayList&lt;DishDetails&gt;();
        String content = null;
        try {
            content = URLConnectionReader.getText("http://"+URLConnectionReader.getIP()+":8080/RestAutomationMobile/get_all_hotdishes.jsp");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        if(content.length() &gt; 0)
        {
            String [] allURLs = content.split(";"); 
            DishDetails item_details;
            for (int i=0; i&lt;allURLs.length; i++) {
                item_details = new DishDetails();
                String [] detail = allURLs[i].split("---");
                item_details.setDishID(Integer.parseInt(detail[0]));
                item_details.setDishCategory(Integer.parseInt(detail[1]));
                item_details.setDishName(detail[2]);
                item_details.setDishDescription(detail[3]);
                item_details.setDishPrice(detail[4]);
                item_details.setDishCalories(detail[5]);
                item_details.setDishDiscount(detail[6]);
                item_details.setDishCookTime(detail[7]);
                item_details.setDishImage(detail[8]);
                item_details.setDishStatus(detail[9]);
                item_details.setDishUnit(detail[10]);

                results.add(item_details);

            }   
        }
        else
        {
        // Toast.makeText(getApplicationContext(), "nothing", Toast.LENGTH_LONG).show();
        }
        return results;
    }


        }
</code></pre>

<p><strong>DishListBaseAdapter.java</strong></p>

<pre><code>    package com.comsats.restaurantandroid.activity;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ImageView.ScaleType;

import com.comsats.restaurantandroid.DishDetails;
import com.comsats.restaurantandroid.R;
import com.comsats.restaurantandroid.store.OrderStore;
import com.comsats.restaurantandroid.util.URLConnectionReader;

public class DishListBaseAdapter extends BaseAdapter {
    private ArrayList&lt;DishDetails&gt; itemDetailsArrayList = null;;
    private ArrayList&lt;DishDetails&gt; itemDetailsArrayOriginal = null;


    private LayoutInflater l_Inflater;
    @SuppressWarnings("unused")
    private String activityType;
    @SuppressWarnings("unused")
    private String catName;
    @SuppressWarnings("unused")
    private String catID;

    public DishListBaseAdapter(Context context, ArrayList&lt;DishDetails&gt; results, String type) {
        itemDetailsArrayList = results;
        l_Inflater = LayoutInflater.from(context);
        activityType = type;
        this.itemDetailsArrayOriginal = new ArrayList&lt;DishDetails&gt;();
        this.itemDetailsArrayOriginal.addAll(results);
    }
    public DishListBaseAdapter(Context context, ArrayList&lt;DishDetails&gt; results, String type, String name, String id) {
        itemDetailsArrayList = results;
        l_Inflater = LayoutInflater.from(context);
        activityType = type;
        catName = name;
        catID = id;
        this.itemDetailsArrayOriginal = new ArrayList&lt;DishDetails&gt;();
        this.itemDetailsArrayOriginal.addAll(results);
    }

    public int getCount() {
        return itemDetailsArrayList.size();
    }

    public Object getItem(int position) {
        return itemDetailsArrayList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = l_Inflater.inflate(R.layout.dish, null);
            holder = new ViewHolder();
            holder.txt_itemName = (TextView) convertView.findViewById(R.id.name);
            holder.txt_itemPrice = (TextView) convertView.findViewById(R.id.price);
            holder.itemImage = (ImageView) convertView.findViewById(R.id.photo);
            holder.quickAdd = (ImageView) convertView.findViewById(R.id.quickAdd);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        final Integer dish_id = itemDetailsArrayList.get(position).getDishID();
        final DishDetails obj = itemDetailsArrayList.get(position);
        holder.quickAdd.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                final AlertDialog.Builder alert = new AlertDialog.Builder(l_Inflater.getContext());

                alert.setTitle("Quantity");
                alert.setMessage("How Many " + itemDetailsArrayList.get(position).getDishUnit());

                // Set an EditText view to get user input 
                final EditText input = new EditText(l_Inflater.getContext());
                input.setText("1");
                alert.setView(input);

                alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    //Toast.makeText(l_Inflater.getContext(), "Item "+input.getText()+" added to your order!", Toast.LENGTH_LONG).show();
                    if(input.getText().toString().equals("") || input.getText().toString() == null)
                    {
                        Toast.makeText(l_Inflater.getContext(), "Please set quantity again", Toast.LENGTH_LONG).show();
                    }
                    else
                    {


                    Float quantity = Float.parseFloat(input.getText().toString());
                    obj.setQuantity(quantity);
                    OrderStore.saveOrderItem(dish_id, obj);
                    Toast.makeText(l_Inflater.getContext(), "Item "+obj.getDishName()+" added to your order!", Toast.LENGTH_LONG).show();

                /*  if(activityType.equals("hot"))
                    {

                    Intent myIntent = new Intent(l_Inflater.getContext(), HotDishesList.class);

                    l_Inflater.getContext().startActivity(myIntent);
                    }else if(activityType.equals("fav"))
                    {
                        Intent myIntent = new Intent(l_Inflater.getContext(), FavouriteDishesList.class);

                        l_Inflater.getContext().startActivity(myIntent);

                    }else if(activityType.equals("mostOrder"))
                    {
                        Intent myIntent = new Intent(l_Inflater.getContext(), MostOrderedDishesList.class);

                        l_Inflater.getContext().startActivity(myIntent);

                    }else if(activityType.equals("normal"))
                    {
                        Bundle basket = new Bundle();
                        basket.putString("id", catID);
                        basket.putString("name", catName);
                        Intent myIntent = new Intent(l_Inflater.getContext(), DishesList.class);
                        myIntent.putExtras(basket);
                        l_Inflater.getContext().startActivity(myIntent);
                    } 
                    */
                    }
                  }
                });

                alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    // Canceled.
                      dialog.cancel();
                  }
                });

                alert.show();

                //OrderStore.saveOrderItem(dish_id, obj);
                //Toast.makeText(l_Inflater.getContext(), "Item "+obj.getDishName()+" added to your order!", Toast.LENGTH_LONG).show();

                //Intent myIntent = new Intent(l_Inflater.getContext(), HotDishesList.class);

                //l_Inflater.getContext().startActivity(myIntent);

                                }
        });

        holder.txt_itemName.setText(itemDetailsArrayList.get(position).getDishName());
        holder.txt_itemPrice.setText(itemDetailsArrayList.get(position).getDishPrice() + " PKR");

        try {
            String thumburl = "http://"+URLConnectionReader.getIP()+":8080/RestAutomationAdmin/uploads/dish/" + itemDetailsArrayList.get(position).getDishImage();
            Drawable drawable = LoadImageFromWebOperations(thumburl);

            holder.itemImage.setImageDrawable(drawable);


            LayoutParams params = (LayoutParams) holder.itemImage.getLayoutParams();
            params.width = 150;
            params.height = 98;

            // existing height is ok as is, no need to edit it
            holder.itemImage.setLayoutParams(params);

            holder.itemImage.setScaleType(ScaleType.FIT_XY);



        } catch (OutOfMemoryError e) {
            System.gc();
            String thumburl = "http://"+URLConnectionReader.getIP()+":8080/RestAutomationAdmin/uploads/dish/" + itemDetailsArrayList.get(position).getDishImage();
            Drawable drawable = LoadImageFromWebOperations(thumburl);

            holder.itemImage.setImageDrawable(drawable);


            LayoutParams params = (LayoutParams) holder.itemImage.getLayoutParams();
            params.width = 150;
            params.height = 98;

            // existing height is ok as is, no need to edit it
            holder.itemImage.setLayoutParams(params);

            holder.itemImage.setScaleType(ScaleType.FIT_XY);



        }
                return convertView;
    }

    static class ViewHolder {
        TextView txt_itemName;
        TextView txt_itemPrice;
        ImageView itemImage;
        ImageView quickAdd;

    }
    private Drawable LoadImageFromWebOperations(String url) {
        try {
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, "src name");
            return d;
        } catch (Exception e) {
            System.out.println("Exc=" + e);
            return null;
        }
    }

    /**
     * Filter
     * @author 9Android.net
     *
     */
       public void filter(String charText) {
            charText = charText.toLowerCase();
            itemDetailsArrayList.clear();
            if (charText.length() == 0) {
                itemDetailsArrayList.addAll(itemDetailsArrayOriginal);
            } else {
                for (DishDetails var : itemDetailsArrayOriginal) {
                    if (var.getDishName().toLowerCase().contains(charText)) {
                        itemDetailsArrayList.add(var);
                    }
                }
            }
            notifyDataSetChanged();
        }
}
</code></pre>

<p>dishes_main.xml</p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/background_color" &gt;
    &lt;include layout="@layout/header2"/&gt;
    &lt;include layout="@layout/top_orderbar" android:visibility="gone" /&gt;

    &lt;LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/roundborder"
android:gravity="center"
android:orientation="horizontal" &gt;

&lt;EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/noborder"
android:padding="8dp"
android:singleLine="true"
android:hint="Search Dish"
android:ems="10"
android:id="@+id/search_dish" &gt;
&lt;requestFocus /&gt;
&lt;/EditText&gt;

&lt;ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="5dp"
android:src="@drawable/search_icon" /&gt;
&lt;/LinearLayout&gt;

    &lt;ListView
        android:id="@+id/dishesList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" &gt;
    &lt;/ListView&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>dish.xml</p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/select_item"

    &gt;
    &lt;ImageView 
        android:id="@+id/photo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="2dp" /&gt;

    &lt;TextView android:id="@+id/name"
        android:textSize="15sp" 
        android:textStyle="bold" 
        android:textColor="#FFFFFF" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:paddingTop="19dp"
        android:layout_marginLeft="120dp"

        /&gt;
    &lt;TextView android:id="@+id/price"
        android:textSize="12sp"  
        android:textColor="#FFFFFF" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_below="@+id/name"
        android:layout_marginLeft="120dp"

        /&gt;
       &lt;ImageView
        android:id="@+id/quickAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="15dp"
        android:paddingTop="23dp"
        android:src="@drawable/quick_add"/&gt;
&lt;/RelativeLayout&gt;
</code></pre>

<p>please help me</p>
