Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
823 views
in Technique[技术] by (71.8m points)

android - 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("
")
            .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;
}

}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...