毕加索IllegalArgumentException [英] Picasso IllegalArgumentException
问题描述
我正在尝试使用毕加索为列表视图加载Facebook照片.
I'm trying to use Picasso to load facebook photos for a listview.
我收到" java.lang.IllegalArgumentException:目标不得为空"
在此行:
.into(holder.userpicture);
如果用户图片ImageView是目标",那么我听不懂.我的猜测是它与我的适配器有关,但我不知道是什么.
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.
非常感谢所有帮助!
编辑
我发现了问题.我犯了一个粗心的错误.在这一行,我忘记了convertView部分:
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;
}
}
推荐答案
大概holder.userpicture
是null
. res/layout/list_item
没有名为userpicture
的小部件,或者您需要清理项目(例如,从Eclipse主菜单中的Project> Clean).
Presumably, holder.userpicture
is null
. Either res/layout/list_item
does not have a widget named userpicture
, or you need to clean your project (e.g., Project > Clean from the Eclipse main menu).
此外,请使用inflate()
的三参数版本,因此,如果将行布局更改为使用RelativeLayout
根,就不会遇到问题.
Also, please use the three-parameter version of inflate()
, so you do not run into problems if you change your row layout to use a RelativeLayout
root.
这篇关于毕加索IllegalArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!