Sugi Almantara
Sugi Almantara

Reputation: 119

Target must be not null (Load an ImageView with Picasso on Dialog)

i have a problem which the log cat said target must be no null i want to show an image in a Dialog by onclick button with Picasso Loader. this my code

viewsim.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(DetailBookingAdmin.this, ""+pathSIM, Toast.LENGTH_SHORT).show();
            final Dialog dialog = new Dialog(DetailBookingAdmin.this);
            dialog.setContentView(R.layout.view_sim);
            dialog.setTitle("SIM");
            final ImageView imgsim = (ImageView)v.findViewById(R.id.img_sim);
           Picasso.with(v.getContext()).load(pathSIM).into(imgsim);
            dialog.show();
        }
    });

Log cat said in line Picasso.with(v.getContext()).load(pathSIM).into(imgsim); target must be not null. Please help me, thanks in advance.

Upvotes: 0

Views: 338

Answers (1)

Sourabh Bans
Sourabh Bans

Reputation: 3134

use layout inflater.

LayoutInflater inflater = getLayoutInflater();
View newView = (View) inflater.inflate(R.layout.view_sim, null);

dialog.setContentView(newView);
final ImageView imgsim = (ImageView)newView.findViewById(R.id.img_sim);
...

Upvotes: 1

Related Questions