Zafer Celaloglu Zafer Celaloglu - 9 days ago 10
Android Question

Picasso IllegalArgumentException Target must not be null

I'm trying to set image by using Picasso library on my project.

When I click image of the View,I'm getting an error on Picasso execution.

Logcat of the app

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;
}


}

Answer

image is the target passed to into. It is what's null.

Ensure that your layout IDs are correct for all configurations and specify @+id/details_image.

Comments