I'm trying to use Picasso to load facebook photos for a listview.
I'm getting "java.lang.IllegalArgumentException: Target must not be null"
on this line:
.into(holder.userpicture);
If the userpicture ImageView is the 'target', then I don't understand. My guess is that it has something to do with my adapter, but I can't figure out what.
All help greatly appreciated!
EDIT
I found the problem. I made a careless mistake. On this line, I forgot the convertView part:
holder.userpicture=(ImageView)findViewById(R.id.userpicture);
Logcat:
06-01 16:37:14.392: E/AndroidRuntime(7885): java.lang.IllegalArgumentException: Target must not be null.
06-01 16:37:14.392: E/AndroidRuntime(7885): at com.squareup.picasso.RequestCreator.into(RequestCreator.java:479)
06-01 16:37:14.392: E/AndroidRuntime(7885): at com.squareup.picasso.RequestCreator.into(RequestCreator.java:462)
06-01 16:37:14.392: E/AndroidRuntime(7885): at com.example.mywebsite.AllProductsActivity$MyAdapter.getView(AllProductsActivity.java:327)
MyAdapter:
public class MyAdapter extends ArrayAdapter<HashMap<String, String>> {
Context context;
int resourceId;
LayoutInflater inflater;
private Context mContext;
ArrayList<HashMap<String, String>> items;
public MyAdapter (Context context, int resourceId, ArrayList<HashMap<String, String>> items)
{
super(context, resourceId, items);
mContext = context;
this.items =items;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
final ViewHolder holder;
if (convertView == null){
convertView = inflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.name = (TextView)convertView.findViewById(R.id.name);
holder.userpicture=(ImageView)findViewById(R.id.userpicture);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
HashMap<String,String> item = (HashMap<String,String> ) items.get(position);
if (item != null)
{
String facebookProfilePicUrl = "http://graph.facebook.com/"+TAG_FACEBOOKID+"/picture?width=100&height=100";
Picasso.with(mContext).load(facebookProfilePicUrl)
.into(holder.userpicture);
holder.name.setText(item.get(TAG_FACEBOOKID));
}
return convertView;
}
public class ViewHolder
{
TextView name;
ImageView userpicture;
}
}