我正在尝试通过在我的项目中使用Picasso库来设置图像.
当我点击View的图像时,我在Picasso执行时遇到错误.
该应用程序的Logcat
java.lang.IllegalArgumentException: Target must not be null.
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:340)
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:326)
at com.zafer.celaloglu.FragmentsandActivities.UnfoldableDetailsFragment.openDetails(UnfoldableDetailsFragment.java:89)
at com.zafer.celaloglu.model.PaintingsAdapter.onClick(PaintingsAdapter.java:52)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
UnfoldableDetailsFragment 89 =
public void openDetails(View coverView, Painting painting) {
ImageView image = (ImageView) coverView.findViewById(R.id.details_image);
TextView title = (TextView) coverView.findViewById(R.id.details_title);
TextView description = (TextView) coverView.findViewById(R.id.details_text);
Picasso.with(getActivity()).load(painting.getimageId()).into(image); ->89. LINE
Log.i("bilgi", "basildi");
title.setText(painting.getTitle());
SpannableBuilder builder = new SpannableBuilder(getActivity());
builder
.createStyle().setFont(Typeface.DEFAULT_BOLD).apply()
.append(R.string.year).append(": ")
.clearStyle()
.append(painting.getYear()).append("\n")
.createStyle().setFont(Typeface.DEFAULT_BOLD).apply()
.append(R.string.location).append(": ")
.clearStyle()
.append(painting.getLocation());
description.setText(builder.build());
mUnfoldableView.unfold(coverView, mDetailsLayout);
}
PaintingAdapter:
public class PaintingsAdapter extends ItemsAdapter<Painting> implements View.OnClickListener {
public PaintingsAdapter(Context context) {
super(context);
setItemsList(Arrays.asList(Painting.getAllPaintings(context.getResources())));
}
@Override
protected View createView(Painting item, int pos, ViewGroup parent, LayoutInflater inflater) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
ViewHolder vh = new ViewHolder();
vh.image = Views.find(view, R.id.list_item_image);
vh.image.setonClickListener(this);
vh.title = Views.find(view, R.id.list_item_title);
view.setTag(vh);
return view;
}
@Override
protected void bindView(Painting item, int pos, View convertView) {
ViewHolder vh = (ViewHolder) convertView.getTag();
vh.image.setTag(item);
Picasso.with(convertView.getContext()).load(item.getimageId()).noFade().into(vh.image);
vh.title.setText(item.getTitle());
}
@Override
public void onClick(View view) {
//Log.i("bilgi", "basildi");
UnfoldableDetailsFragment fm = new UnfoldableDetailsFragment();
fm.openDetails(view, (Painting)view.getTag()); -->HERE IS 52. line
Log.i("bilgi", "basildi");
}
private static class ViewHolder {
ImageView image;
TextView title;
}
}
解决方法:
图像是传入的目标.它是空的.
确保所有配置的布局ID都正确,并指定@ id / details_image.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。