title: Display image in GridView using Picasso
body: <p>I want to build an app that displays images in a gridview by using the picasso library. This is my code. The image didn't load. In Picasso log, after request it always error to load. Can you help me ?Please Thank you</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>CustomGridViewAdapter.Java</p>
  
  <pre><code>import android.app.Activity;
  import android.content.ClipData;
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import com.squareup.picasso.Picasso;
  
  import java.util.ArrayList;
  
  /**
   * Created by Nicky-PC on 4/9/2016.
   */
  public class CustomGridViewAdapter extends ArrayAdapter&lt;gridItem&gt; {
      Context context;
      int layoutResourceId;
      ArrayList&lt;gridItem&gt; data = new ArrayList&lt;gridItem&gt;();
  
      public CustomGridViewAdapter(Context context, int layoutResourceId,
                                   ArrayList&lt;gridItem&gt; data) {
          super(context, layoutResourceId, data);
          this.layoutResourceId = layoutResourceId;
          this.context = context;
          this.data = data;
      }
  
      public void setGridData(ArrayList&lt;gridItem&gt; mGridData)
      {
          this.data=mGridData;
          notifyDataSetChanged();
      }
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View row = convertView;
          RecordHolder holder;
  
          if (row == null) {
              LayoutInflater inflater = ((Activity) context).getLayoutInflater();
              row = inflater.inflate(layoutResourceId, parent, false);
              holder = new RecordHolder();
              holder.txtTitle = (TextView) row.findViewById(R.id.tvItem);
              holder.imageItem = (ImageView) row.findViewById(R.id.imageView);
              row.setTag(holder);
          } else {
              holder = (RecordHolder) row.getTag();
          }
          gridItem item = data.get(position);
          holder.txtTitle.setText(item.getBarang());
          Picasso.with(context).
                  load(item.getImageUrl()).
                  into(holder.imageItem);
          return row;
      }
  
      static class RecordHolder {
          TextView txtTitle;
          ImageView imageItem;
      }
  }
  </code></pre>
  
  <p>MainActivity.Java   </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  
  import android.app.Activity;
  import android.media.Image;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v7.app.ActionBarActivity;
  import android.util.Log;
  import android.widget.GridView;
  import android.widget.ImageView;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  import android.widget.Toast;
  
  import com.squareup.picasso.Picasso;
  
  import org.apache.http.NameValuePair;
  import org.apache.http.message.BasicNameValuePair;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  public class MainActivity extends ActionBarActivity {
      JSONParser jParser= new JSONParser();
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; nameList;
      JSONArray names=null;
      GridView data;
      private static final String URL_TEST_BARANG= "http://lomapod.azurewebsites.net/readBarang.php";
      private static final String TAG_PESAN = "message";
      private static final String TAG_HASIL = "result";
      private static final String TAG_BARANG = "nama_barang";
      private static final String TAG_IMAGE= "image_name";
      ImageView imageview;
      CustomGridViewAdapter mGridAdapter;
      ArrayList&lt;gridItem&gt; mGridData;
      public  MainActivity()
      {}
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          data=(GridView) findViewById(R.id.lvSeller);
          nameList= new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          imageview =(ImageView) findViewById(R.id.imageView);
          mGridData=new ArrayList&lt;&gt;();
          mGridAdapter=new CustomGridViewAdapter(this,R.layout.grid_item,mGridData);
  
  
          new AmbilDataJson("1").execute();
      }
  
  
      public class AmbilDataJson extends AsyncTask&lt;String,String,String&gt; {
  
          String id;
          int sukses=0;
  
          public AmbilDataJson(String id) {
              this.id=id;
          }
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
          }
  
          @Override
          protected String doInBackground(String... args) {
  
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              params.add(new BasicNameValuePair("id_penjual",id));
              try
              {
  
                  JSONObject json = jParser.makeHttpRequest(URL_TEST_BARANG, "GET", params);
                  gridItem item=null;
                  if(json != null)
                  {
                      sukses = json.getInt(TAG_PESAN);
                      if(sukses == 0)
                      {
                          nameList = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
                          Log.d("Semua Nama: ", json.toString());
                          names = json.getJSONArray(TAG_HASIL);
  
                          for(int i = 0; i &lt; names.length();i++)
                          {
                              JSONObject c = names.getJSONObject(i);
                              String barang = c.getString(TAG_BARANG);
                              String image = "lomapod.esy.es/assets/"+c.getString(TAG_IMAGE);
  
                              item = new gridItem();
                              item.setBarang(barang);
                              item.setImageUrl(image);
  
                              HashMap&lt;String,String&gt; map = new HashMap&lt;String,String&gt;();
  
                              map.put(TAG_BARANG,barang);
                              map.put(TAG_IMAGE,image);
                              nameList.add(map);
                              mGridData.add(item);
                          }
                      }
                  }
              }catch(JSONException e)
              {
                  e.printStackTrace();
              }
  
              return null;
          }
  
          @Override
          protected void onPostExecute(String s) {
              if(sukses == 0)
              {
                  CustomGridViewAdapter adapter = new CustomGridViewAdapter(
                          MainActivity.this,R.layout.grid_item,mGridData);
                  if(mGridData.size()&gt;0)
                  {
                      mGridAdapter.setGridData(mGridData);
                      data.setAdapter(adapter);
                  }
                  else
                      Toast.makeText(getApplicationContext(),"Error - No Data      Available", Toast.LENGTH_SHORT).show();
  
              }
              else
              {
                  Toast.makeText(MainActivity.this,"Failed",Toast.LENGTH_LONG);
              }
          }
      }
  }
  </code></pre>