title: How to set images in gridview with arraylist of urls?
body: <p><strong>SampleGridViewAdapter.java</strong></p>
  
  <pre><code>package com.alifinteractive.viewtext;
  
  import android.content.Context;
  import android.database.DataSetObserver;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.os.AsyncTask;
  import android.util.Log;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ImageView;
  
  import java.io.InputStream;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  class SampleGridViewAdapter extends ArrayAdapter {
      private final Context context;
      List&lt;String&gt; urls;
      String[] strBook;
      Bitmap bmp;
  
      public SampleGridViewAdapter(Context context, ArrayList&lt;String&gt; urls) {
          super(context, R.layout.list_image);
          this.context = context;
          this.urls = urls;
          Log.i("DDDDDDDDDD", String.valueOf(urls));
          Object[] mStringArray = urls.toArray();
          strBook = Arrays.copyOf(mStringArray, mStringArray.length, String[].class);
          for (int i = 0; i &lt; strBook.length; i++) {
              Log.i("GGGGGGGGGGG", String.valueOf(strBook[i]));
          }
      }
  
      @Override
      public View getView(final int position, View view, ViewGroup parent) {
          if (view == null) {
              view = new ImageView(context);
          }
          loadBookIcons(view, position);
          return view;
      }
  
      private void loadBookIcons(final View view, final int position) {
          new AsyncTask&lt;Void, Void, Void&gt;() {
              @Override
              protected Void doInBackground(Void... params) {
  
                  try {
                      InputStream in = new URL(strBook[position]).openStream();
                      bmp = BitmapFactory.decodeStream(in);
                  } catch (Exception e) {
                      Log.i("ERRORRRRRR", e.toString());
                  }
                  return null;
              }
  
              @Override
              protected void onPostExecute(Void result) {
                  if (bmp != null) {
                      ((ImageView) view).setImageBitmap(bmp);
                  }
              }
          }.execute();
      }
  
      @Override
      public int getViewTypeCount() {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public boolean hasStableIds() {
          // TODO Auto-generated method stub
          return false;
      }
  
      @Override
      public boolean isEmpty() {
          // TODO Auto-generated method stub
          return false;
      }
  
      @Override
      public void registerDataSetObserver(DataSetObserver arg0) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void unregisterDataSetObserver(DataSetObserver arg0) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public boolean areAllItemsEnabled() {
          // TODO Auto-generated method stub
          return false;
      }
  
      @Override
      public boolean isEnabled(int arg0) {
          // TODO Auto-generated method stub
          return false;
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
      }
  
  }
  </code></pre>
  
  <p>this is my home <code>Fragment</code> on which I want to set the <code>GridView</code> </p>
  
  <pre><code>package com.alifinteractive.viewtext;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  
  import org.json.JSONArray;
  import org.json.JSONObject;
  
  import java.util.ArrayList;
  
  public class Home_new extends Fragment {
      //Login login;
      String json;
      JSONObject jsonObj;
      String imageUrl;
      //String name;
      ImageView img;
      ArrayList&lt;String&gt; Urls = new ArrayList&lt;String&gt;();
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_home1, container, false);
          //GridView grid=(GridView)rootView.findViewById(R.id.grid_view);
          //grid.setAdapter(new SampleGridViewAdapter(getActivity(),Urls));
          // username=Login.getUserObject(getActivity(), "username");
          // password=Login.getUserObject(getActivity(), "password");
          String oldjson = Login.getUserObject(getActivity(), "order_json");
          json = oldjson.replaceAll("\\\\", "");
          Log.i("QQQQQQQQ", json);
          try {
              JSONArray results = new JSONObject(json).getJSONArray("CustomerOrders");
  
              for (int i = 0; i &lt; 10; i++) {
                  JSONObject menuObject = results.getJSONObject(i);
                  Log.i("ooooooooo", String.valueOf(menuObject));
                  imageUrl = menuObject.getString("image");
                  Log.i("FFFFFFF", imageUrl);
                  Urls.add(i, imageUrl);
  
                  Log.i("LLLLLLL", String.valueOf(Urls));
              }
  
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          Log.i("ZZZZZZZ", String.valueOf(Urls));
          // TODO Auto-generated catch block
          return rootView;
      }
  }
  </code></pre>
  
  <p>I want to set the <code>adapter</code> on <code>GridView</code> but getting error , help me thanks in advance</p>